Class-Tables
view release on metacpan or search on metacpan
lib/Class/Tables.pm view on Meta::CPAN
my ( %CLASS, %OBJ, %TABLE_MAP, $SCHEMA_CACHE );
######################
## public interface ##
######################
sub import {
my ($class, %args) = @_;
$CASCADE = $args{cascade} if exists $args{cascade};
$INFLECT = $args{inflect} if exists $args{inflect};
$SCHEMA_CACHE = $args{cache} if exists $args{cache};
}
sub dbh {
my ($super, $dbh) = @_;
croak "No DBH given" unless $dbh;
($DBH, $DB_DRIVER, %CLASS, %OBJ, %TABLE_MAP) =
($dbh, "Class::Tables::$dbh->{Driver}{Name}");
lib/Class/Tables.pm view on Meta::CPAN
}
sub delete {
my $self = shift;
my $id = $self->id;
my $class = ref $self;
my $table = $class->_table;
my $id_col = $class->_id_col;
if ($CASCADE) {
my @cascade = grep { $CLASS{$class}{accessors}{$_}{type} eq '1-to-n' }
keys %{ $CLASS{$class}{accessors} };
for my $accessor (@cascade) {
$_->delete for $self->$accessor;
}
}
sql_do("delete from $table where $id_col=?", $id);
delete $OBJ{$class}{$id};
}
use overload
lib/Class/Tables.pm view on Meta::CPAN
=head2 Public Interface
=over
=item C<< use Class::Tables %args >>
Valid argument keys are:
=over
=item cascade
Takes a boolean value indicating whether to perform cascading deletes. See
C<delete> below for information on cascading deletes. If you need to change
cascading delete behavior on the fly, localize C<$Class::Tables::CASCADE>.
=item inflect
Takes a boolean value indicating whether to use
L<Lingua::EN::Inflect|Lingua::EN::Inflect> for plural & singular nouns. See
L<Plural And Singular Nouns> for more information on noun pluralization.
lib/Class/Tables.pm view on Meta::CPAN
mapping, and on each subsequent execution, uses the cache to keep from doing
the mapping again. If your database's schema changes, simply empty the cache
file to force a re-mapping.
You can omit this arg or pass a false value to disable this feature.
=back
The default behavior is:
use Class::Tables cascade => 1, inflect => 1, cache => undef;
=item C<< Class::Tables->dbh($dbh) >>
You must pass Class::Tables an active database handle before you can use any
generated object classes.
=back
=head2 Object Instance Methods
( run in 0.480 second using v1.01-cache-2.11-cpan-49f99fa48dc )