Transactional/AutoCommit.pm

filter: Statementstmt 100% 35 / 35 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 4 totaltotal 91.0% 51 / 56 CC 4 SCAR 3.6
CC
4
Cov
98%
register
2.0
resource_expired
2.0
commit
2.0
CRAP 1.4
« Transactional/TXN/Nested.pm ↑ Summary Transactional/TXN.pm »
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
BranchTrueFalseTotal
if $self->finished 0 9 9
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
BranchTrueFalseTotal
if (keys %{$self->resources;} == 0) 8 1 9
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
BranchTrueFalseTotal
unless ($self->finished) 7 1 8
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__
« Transactional/TXN/Nested.pm ↑ Summary Transactional/TXN.pm »