Jifty-DBI
view release on metacpan or search on metacpan
lib/Jifty/DBI/Record.pm view on Meta::CPAN
=head1 SYNOPSIS
package MyRecord;
use base qw/Jifty::DBI::Record/;
=head1 DESCRIPTION
Jifty::DBI::Record encapsulates records and tables as part of the L<Jifty::DBI>
object-relational mapper.
=head1 METHODS
=head2 new ARGS
Instantiate a new, empty record object.
ARGS is a hash used to pass parameters to the C<_init()> function.
Unless it is overloaded, the _init() function expects one key of
'handle' with a value containing a reference to a Jifty::DBI::Handle
object.
=cut
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
bless( $self, $class );
$self->_init_columns() unless $self->COLUMNS;
$self->input_filters('Jifty::DBI::Filter::Truncate');
if ( scalar(@_) == 1 ) {
Carp::cluck(
"new(\$handle) is deprecated, use new( handle => \$handle )");
$self->_init( handle => shift );
} else {
$self->_init(@_);
}
return $self;
}
# Not yet documented here. Should almost certainly be overloaded.
sub _init {
my $self = shift;
my %args = (@_);
if ( $args{'handle'} ) {
$self->_handle( $args{'handle'} );
}
}
sub import {
my $class = shift;
my ($flag) = @_;
if ( $class->isa(__PACKAGE__) and defined $flag and $flag eq '-base' ) {
my $descendant = (caller)[0];
unless ( $descendant->isa($class) ) {
no strict 'refs';
push @{ $descendant . '::ISA' }, $class
}
shift;
# run the schema callback
my $callback = shift;
$callback->() if $callback;
}
$class->SUPER::import(@_);
# Turn off redefinition warnings in the caller's scope
@_ = ( warnings => 'redefine' );
goto &warnings::unimport;
}
=head2 id
Returns this row's primary key.
=cut
sub id {
my $pkey = $_[0]->_primary_key();
my $ret = $_[0]->{'values'}->{$pkey};
return $ret;
}
=head2 primary_keys
Return a hash of the values of our primary keys for this function.
=cut
sub primary_keys {
my $self = shift;
my %hash
= map { $_ => $self->{'values'}->{$_} } @{ $self->_primary_keys };
return (%hash);
}
=head2 _accessible COLUMN ATTRIBUTE
Private method.
DEPRECATED
Returns undef unless C<COLUMN> has a true value for C<ATTRIBUTE>.
Otherwise returns C<COLUMN>'s value for that attribute.
=cut
sub _accessible {
my $self = shift;
my $column_name = shift;
my $attribute = lc( shift || '' );
my $col = $self->column($column_name);
( run in 1.705 second using v1.01-cache-2.11-cpan-5e09290becf )