Alzabo
view release on metacpan or search on metacpan
lib/Alzabo/Runtime/Row.pm view on Meta::CPAN
)
);
return 0;
}
sub _no_such_row_error
{
my $self = shift;
my $err = 'Unable to find a row in ' . $self->table->name . ' where ';
my @vals;
while ( my( $k, $v ) = each %{ $self->{pk} } )
{
$v = '<NULL>' unless defined $v;
my $val = "$k = $v";
push @vals, $val;
}
$err .= join ', ', @vals;
no_such_row_exception $err;
}
sub STORABLE_freeze
{
my $self = shift;
my $cloning = shift;
my %data = %$self;
my $table = delete $data{table};
$data{schema} = $table->schema->name;
$data{table_name} = $table->name;
my $ser = eval { Storable::nfreeze(\%data) };
storable_exception $@ if $@;
return $ser;
}
sub STORABLE_thaw
{
my ( $self, $cloning, $ser ) = @_;
my $data = eval { Storable::thaw($ser) };
storable_exception $@ if $@;
%$self = %$data;
my $s = Alzabo::Runtime::Schema->load_from_file( name => delete $self->{schema} );
$self->{table} = $s->table( delete $self->{table_name} );
return $self;
}
BEGIN
{
# dumb hack to fix bugs in Storable 2.00 - 2.03 w/ a non-threaded
# Perl
#
# Basically, Storable somehow screws up the hooks business the
# _first_ time an object from a class with hooks is stored. So
# we'll just _force_ it do it once right away.
if ( $Storable::VERSION >= 2 && $Storable::VERSION <= 2.03 )
{
eval <<'EOF';
{ package ___name; sub name { 'foo' } }
{ package ___table; @table::ISA = '___name'; sub schema { bless {}, '___name' } }
my $row = bless { table => bless {}, '___table' }, __PACKAGE__;
Storable::thaw(Storable::nfreeze($row));
EOF
}
}
1;
__END__
=head1 NAME
Alzabo::Runtime::Row - Row objects
=head1 SYNOPSIS
use Alzabo::Runtime::Row;
my $row = $table->row_by_pk( pk => 1 );
$row->select('foo');
$row->update( bar => 5 );
$row->delete;
=head1 DESCRIPTION
These objects represent actual rows from the database containing
actual data. In general, you will want to use the
L<C<Alzabo::Runtime::Table>|Alzabo::Runtime::Table> object to retrieve
rows. The L<C<Alzabo::Runtime::Table>|Alzabo::Runtime::Table> object
can return either single rows or L<row
cursors|Alzabo::Runtime::RowCursor>.
=head1 ROW STATES
Row objects can have a variety of states. Most row objects are
"live", which means they represent an actual row object. A row can be
changed to the "deleted" state by calling its C<delete()> method.
This is a row that no longer exists in the database. Most method
calls on rows in this state cause an exception.
There is also a "potential" state, for objects which do not represent
actual database rows. You can call L<C<make_live()>|make_live> on
these rows in order to change their state to "live".
Finally, there is an "in cache" state, which is identical to the
"live" state, except that it is used for object's that are cached via
( run in 1.880 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )