blib/lib/DBIx/Class/Storage/TxnEndHook.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 6 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 4 / 4 totaltotal 97.0% 65 / 67 CC 5 SCAR 5.1
CC
5
Cov
98%
txn_commit
3.0
add_txn_end_hook
2.0
__ANON__
2.0
CRAP 1.7
« _build/lib/MyBuilder.pm ↑ Summary blib/lib/DBIx/Class/Schema/TxnEndHook.pm »
1 package DBIx::Class::Storage::TxnEndHook;
2 2 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use base 'DBIx::Class::Storage';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 __PACKAGE__->mk_group_accessors(simple => qw/_hooks/);
10  
11 2 our $VERSION = "0.01";
12  
13 sub new {
14 9 ▶ my $self = shift->next::method(@_);
Subroutine new: called CC=1 SCAR=0.0
Pod documented
15 9 $self->_hooks([]);
16 9 $self;
17 }
18  
19 sub add_txn_end_hook {
20 15 ▶ my ($self, $hook) = @_;
Subroutine add_txn_end_hook: called CC=2 SCAR=6.9
Pod documented
21  
22 15 ▶ unless ( $self->transaction_depth > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->transaction_depth > 0) 1 14 15
23 1 $self->throw_exception('only can call add_txn_end_hook in transaction');
24 }
25  
26 14 push @{ $self->_hooks }, $hook;
27 }
28  
29 sub txn_commit {
30 8 ▶ my $self = shift;
Subroutine txn_commit: called CC=3 SCAR=11.0
Pod documented
31 8 my $is_last_txn = $self->transaction_depth == 1;
32 8 my @ret = $self->next::method(@_);
33  
34 8 ▶ if ( $is_last_txn && @{ $self->_hooks } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_last_txn and @{$self->_hooks;}) 7 1 8
Condition66%2/3
$is_last_txn and @{$self->_hooks;}
!ll&&!rl&&r
107
MC/DC50%1/2
$is_last_txn and @{$self->_hooks;}
$is_last_txn @{$self->_hooks;}
Truth table66%2/3
A and B
A= $is_last_txnB= @{$self->_hooks;}
ABresult
0X0
100
111
35 try {
36 7 ▶ while ( my $hook = shift @{ $self->_hooks } ) {
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (my $hook = shift @{$self->_hooks;}) 12 6 18
37 12 $hook->();
38 }
39 }
40 catch {
41 1 ▶ $self->_hooks([]);
Subroutine __ANON__: called CC=1 SCAR=0.0
42 1 warn $_;
43 7 };
44 }
45  
46 8 @ret;
47 }
48  
49 sub txn_rollback {
50 1 ▶ my $self = shift;
Subroutine txn_rollback: called CC=1 SCAR=0.0
Pod documented
51 1 my @ret = $self->next::method(@_);
52 1 $self->_hooks([]);
53 1 @ret;
54 }
55  
56 2 1;
57 __END__
« _build/lib/MyBuilder.pm ↑ Summary blib/lib/DBIx/Class/Schema/TxnEndHook.pm »