| 1 | #!/usr/bin/perl | ||||||||||
| 2 | |||||||||||
| 3 | package Directory::Transactional::AutoCommit; | ||||||||||
| 4 | 2 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | $Directory::Transactional::AutoCommit::VERSION = '0.09'; | |||||||||
| 6 | } | ||||||||||
| 7 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use Scope::Guard; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 2 | ▶ | use namespace::clean -except => 'meta'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 2 | ▶ | use Hash::Util::FieldHash::Compat qw(fieldhash); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 2 | has manager => ( | |||||||||
| 16 | isa => "Directory::Transactional", | ||||||||||
| 17 | is => "ro", | ||||||||||
| 18 | required => 1, | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 2 | has finished => ( | |||||||||
| 22 | isa => "Bool", | ||||||||||
| 23 | is => "rw", | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | has resources => ( | ||||||||||
| 27 | isa => "HashRef", | ||||||||||
| 28 | is => "ro", | ||||||||||
| 29 | 8 | ▶ | default => sub { fieldhash my %h }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 2 | ); | |||||||||
| 31 | |||||||||||
| 32 | 9 | ▶ | sub register { | ||||||||
|
Subroutine
register: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 33 | 9 | my ( $self, @resources ) = @_; | |||||||||
| 34 | |||||||||||
| 35 | 9 | ▶ | die "blah" if $self->finished; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | |||||||||||
| 37 | 9 | ▶ | my $guard = Scope::Guard->new(sub { $self->resource_expired }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 38 | |||||||||||
| 39 | 9 | @{ $self->resources }{ @resources } = ( ($guard) x @resources ); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 9 | ▶ | sub resource_expired { | ||||||||
|
Subroutine
resource_expired: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 43 | 9 | my $self = shift; | |||||||||
| 44 | |||||||||||
| 45 | 9 | ▶ | if ( keys %{ $self->resources } == 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 8 | $self->commit; | |||||||||
| 47 | } | ||||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 8 | ▶ | sub commit { | ||||||||
|
Subroutine
commit: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 51 | 8 | my $self = shift; | |||||||||
| 52 | |||||||||||
| 53 | 8 | ▶ | unless ( $self->finished ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 7 | $self->manager->txn_commit; | |||||||||
| 55 | 7 | $self->finished(1); | |||||||||
| 56 | } | ||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 8 | ▶ | sub DEMOLISH { | ||||||||
|
Subroutine
DEMOLISH: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 60 | 8 | my $self = shift; | |||||||||
| 61 | 8 | $self->finished(1); # don't commit, we're being destroyed because the txn was rolled back or comitted | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 65 | |||||||||||
| 66 | 2 | __PACKAGE__ | |||||||||
| 67 | |||||||||||
| 68 | __END__ | ||||||||||