EntityModel
view release on metacpan or search on metacpan
lib/EntityModel/Storage.pm view on Meta::CPAN
}
=head2 next
Returns next element for the given ID.
=cut
sub next {
my $self = shift;
my ($prev, $next) = $self->adjacent(@_);
return $next;
}
=head2 outer
Returns first and last IDs for the given entity.
=cut
sub outer {
my $self = shift;
my %args = @_;
die "Virtual!";
}
=head2 first
Returns first active ID for the given entity.
=cut
sub first {
my $self = shift;
my ($first, $last) = $self->outer(@_);
return $first;
}
=head2 last
Returns last active ID for the given entity.
=cut
sub last {
my $self = shift;
my ($first, $last) = $self->outer(@_);
return $last;
}
=head2 transaction_start
Mark the start of a transaction.
=cut
sub transaction_start {
my $self = shift;
my $tran = shift;
# TODO weaken?
$self->transaction->push($tran);
return $self;
}
=head2 transaction_rollback
Roll back a transaction.
=cut
sub transaction_rollback {
my $self = shift;
my $tran = shift;
die "No transaction in progress" unless $self->transaction->count;
die "Mismatched transaction" unless $tran ~~ $self->transaction->last;
}
=head2 transaction_commit
Commit this transaction to storage - makes everything done within the transaction permanent
(or at least to the level the storage class supports permanence).
=cut
sub transaction_commit {
my $self = shift;
my $tran = shift;
die "No transaction in progress" unless $self->transaction->count;
die "Mismatched transaction" unless $tran ~~ $self->transaction->last;
}
=head2 transaction_end
Release the transaction on completion.
=cut
sub transaction_end {
my $self = shift;
my $tran = shift;
die "No transaction in progress" unless $self->transaction->count;
die "Mismatched transaction" unless $tran ~~ $self->transaction->last;
$self->transaction->pop;
return $self;
}
sub backend_ready { shift->{backend_ready} }
sub wait_for_backend {
my $self = shift;
my $code = shift;
return $code->($self) if $self->backend_ready;
$self->add_handler_for_event( backend_ready => sub { $code->(@_); 0 });
return $self;
}
sub DESTROY {
my $self = shift;
die "Active transactions" if $self->transaction->count;
}
( run in 1.134 second using v1.01-cache-2.11-cpan-39bf76dae61 )