Model/Transaction.pm

filter: Statementstmt 35.2% 18 / 51 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 3 totaltotal 26.8% 22 / 82 CC 9 SCAR 22.9
CC
9
Cov
26%
__ANON__
20.5
DESTROY
12.0
rollback
6.0
CRAP 9.9
« Model/Mixin.pm ↑ Summary Model/Driver.pm »
1 package Data::Model::Transaction;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 4 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 $Carp::Internal{(__PACKAGE__)}++;
6  
7 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
8 0 my($class, $model) = @_;
9 0 $model->txn_begin;
10 0 bless [ 0, $model, ], $class;
11 }
12  
13 0 ▶sub rollback {
Subroutine rollback: not called CC=2 SCAR=17.9
Pod undocumented
14 0 ▶ return if $_[0]->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0][0] 0 0 0
15 0 $_[0]->[1]->txn_rollback;
16 0 $_[0]->[0] = 1;
17 }
18  
19 0 ▶sub commit {
Subroutine commit: not called CC=2 SCAR=17.9
Pod undocumented
20 0 ▶ return if $_[0]->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0][0] 0 0 0
21 0 $_[0]->[1]->txn_commit;
22 0 $_[0]->[0] = 1;
23 }
24  
25 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=3 SCAR=24.8
26 0 my($dismiss, $model) = @{ $_[0] };
27 0 ▶ return if $dismiss;
Branch: 1 branch
BranchTrueFalseTotal
if $dismiss 0 0 0
28  
29 {
30 0 local $@;
31 0 eval { $model->txn_rollback };
32 0 my $rollback_exception = $@;
33 0 ▶ if($rollback_exception) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rollback_exception) 0 0 0
34 0 Carp::croak "Rollback failed: ${rollback_exception}";
35 }
36 }
37 }
38  
39 # handle of Data::Model model methods
40 4 my @model_methods = qw/
41 lookup lookup_multi get get_multi
42 set set_multi replace update update_direct
43 delete delete_direct delete_multi
44 /;
45 4 for my $method (@model_methods) {
46 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
47 48 ▶ *{$method} = sub {
Subroutine __ANON__: not called CC=5 SCAR=30.2
48 4 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 0 my $self = shift;
50  
51 # check the on transaction
52 0 ▶ Carp::croak "You cannot use $method method, Because you leave the transaction scope." if $self->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[0] 0 0 0
53  
54 # check driver
55 0 my $datamodel = $self->[1];
56 0 my $model = $_[0];
57 0 my $driver;
58 0 ▶ if (ref($model) && $model->isa('Data::Model::Row')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $model and $model->isa('Data::Model::Row')) { } 0 0 0
Condition0%0/3
ref $model and $model->isa("Data::Model::Row")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $model and $model->isa("Data::Model::Row")
ref $model $model->isa("Data::Model::Row")
Truth table0%0/3
A and B
A= ref $modelB= $model->isa("Data::Model::Row")
ABresult
0X0
100
111
59 0 my $schema = $datamodel->_get_schema_by_row($model);
60 0 $model = $schema->model;
61 0 $driver = $schema->driver;
62 } else {
63 0 $driver = $datamodel->get_schema($model)->driver;
64 }
65 0 ▶ unless (($datamodel->get_base_driver)+0 == $driver+0) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($datamodel->get_base_driver + 0 == $driver + 0) 0 0 0
66 0 Carp::croak "'$model' has driver is not same base_driver";
67 }
68  
69 0 local $datamodel->{active_transaction} = 0;
70 0 $datamodel->$method(@_);
71 48 };
72 }
73  
74 4 1;
75  
76 __END__
« Model/Mixin.pm ↑ Summary Model/Driver.pm »