ORM/Ta.pm

filter: Statementstmt 75.6% 28 / 37 Branchbran 72.2% 13 / 18 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 66.6% 2 / 3 Podpod 0.0% 0 / 2 totaltotal 64.0% 48 / 75 CC 13 SCAR 19.9
CC
13
Cov
70%
DESTROY
8.6
new
6.3
die_handler
6.0
CRAP 7.3
« ORM/StatResultSet.pm ↑ Summary ORM/Stat.pm »
1 #
2 # DESCRIPTION
3 # PerlORM - Object relational mapper (ORM) for Perl. PerlORM is Perl
4 # library that implements object-relational mapping. Its features are
5 # much similar to those of Java's Hibernate library, but interface is
6 # much different and easier to use.
7 #
8 # AUTHOR
9 # Alexey V. Akimov <akimov_alexey@sourceforge.net>
10 #
11 # COPYRIGHT
12 # Copyright (C) 2005-2006 Alexey V. Akimov
13 #
14 # This library is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU Lesser General Public
16 # License as published by the Free Software Foundation; either
17 # version 2.1 of the License, or (at your option) any later version.
18 #
19 # This library is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # Lesser General Public License for more details.
23 #
24 # You should have received a copy of the GNU Lesser General Public
25 # License along with this library; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #
28  
29 package ORM::Ta;
30  
31 5 $VERSION = 0.8;
32  
33 5 my $die;
34 my $die_eval;
35 5 my $die_handler_enabled;
36 5 my $old_die_handler;
37  
38 sub new
39 57 ▶{
Subroutine new: called CC=6 SCAR=18.3
Pod undocumented
40 57 my $class = shift;
41 57 my %arg = @_;
42 57 my $self = bless {}, $class;
43  
44 57 ▶ unless( $arg{class}->_current_transaction )
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg{"class"}->_current_transaction) 10 47 57
45 {
46 10 $die = undef;
47
48 10 $self->{class} = $arg{class};
49 10 ▶ $self->{error} = $arg{error} || ORM::Error->new;
Condition33%1/3
$arg{'error'} || 'ORM::Error'->new
l!l&&r!l&&!r
1000
MC/DC0%0/2
$arg{'error'} || 'ORM::Error'->new
$arg{'error'} 'ORM::Error'->new
Truth table33%1/3
A || B
A= $arg{'error'}B= 'ORM::Error'->new
ABresult
1X1
011
000
50 10 $self->{eval} = $^S;
51  
52 10 ▶ unless( $die_handler_enabled )
Branch: 1 branch
BranchTrueFalseTotal
unless ($die_handler_enabled) 1 9 10
53 {
54 1 $die_handler_enabled = 1;
55 1 $old_die_handler = $::SIG{__DIE__};
56 1 $::SIG{__DIE__} = \&die_handler;
57 }
58  
59 10 ▶ unless( $self->{error}->fatal )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"error"}->fatal) 10 0 10
60 {
61 10 my $error = ORM::Error->new;
62 10 $self->{class}->_db->begin_transaction( error=>$error );
63 10 $self->{class}->_current_transaction( 1 );
64 10 ▶ if( $error->fatal )
Branch: 1 branch
BranchTrueFalseTotal
if ($error->fatal) 0 10 10
65 {
66 0 $self->{error}->add( error=>$error );
67 0 $self->{not_started} = 1;
68 }
69 }
70 }
71  
72 57 return $self;
73 }
74  
75 sub DESTROY
76 57 ▶{
Subroutine DESTROY: called CC=7 SCAR=21.5
77 57 my $self = shift;
78  
79 57 ▶ $self->{class} && $self->{class}->_current_transaction( undef );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"class"} and $self->{"class"}->_current_transaction(undef) 10 47 57
80  
81 57 ▶ if( $self->{not_started} || !$self->{class} )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'not_started'} or not $self->{'class'}) { } 47 10 57
elsif ($die and $die_eval eq $self->{'eval'}) { } 0 10 10
elsif ($self->{'error'}->fatal) { } 1 9 10
Condition66%2/3
$self->{"not_started"} or not $self->{"class"}
l!l&&r!l&&!r
04710
MC/DC50%1/2
$self->{"not_started"} or not $self->{"class"}
$self->{"not_started"} not $self->{"class"}
Truth table66%2/3
A or not(B)
A= $self->{"not_started"}B= not $self->{"class"}
ABresult
1X1
011
000
82 {
83 # nothing to do
84 }
85 ▶ elsif( $die && $die_eval eq $self->{eval} )
Condition33%1/3
$die and $die_eval eq $self->{"eval"}
!ll&&!rl&&r
1000
MC/DC0%0/2
$die and $die_eval eq $self->{"eval"}
$die $die_eval eq $self->{"eval"}
Truth table33%1/3
A and B
A= $dieB= $die_eval eq $self->{"eval"}
ABresult
0X0
100
111
86 {
87 0 $die = undef;
88 0 $self->{error}->add_fatal( "Transaction rolled back because of thrown exception" );
89 0 $self->{class}->_db->rollback_transaction( error=>$self->{error} );
90 }
91 elsif( $self->{error}->fatal )
92 {
93 1 $self->{class}->_db->rollback_transaction( error=>$self->{error} );
94 }
95 else
96 {
97 9 $self->{class}->_db->commit_transaction( error=>$self->{error} );
98 }
99 }
100  
101 sub die_handler
102 0 ▶{
Subroutine die_handler: not called CC=2 SCAR=17.9
Pod undocumented
103 0 $die = 1;
104 0 $die_eval = $^S;
105 0 ▶ $old_die_handler && &{$old_die_handler}( @_ );
Branch: 1 branch
BranchTrueFalseTotal
$old_die_handler and &{$old_die_handler;}(@_) 0 0 0
106 }
107  
108 5 1;
« ORM/StatResultSet.pm ↑ Summary ORM/Stat.pm »