LogAny/db.pm

filter: Statementstmt 56.0% 144 / 257 Branchbran 33.8% 48 / 142 Conditioncond 28.2% 22 / 78 MC/DCmcdc 4.3% 2 / 46 Subroutinesub 64.5% 20 / 31 Podpod 93.7% 15 / 16 totaltotal 44.0% 251 / 570 SCAR 75.4
CC
103
Cov
45%
_error_handler
279.2
selectrow_array
56.0
prepare_cached
30.0
CRAP 1881.2
↑ Summary LogAny/st.pm »
1 # $Id: db.pm 245 2006-07-25 14:20:59Z martin $
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Module::Loaded;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package DBIx::LogAny::db;
9 2 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 @DBIx::LogAny::db::ISA = qw(DBI::db DBIx::LogAny);
11 2 ▶use DBIx::LogAny::Constants qw (:masks $LogMask);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # $_glogger is not relied upon - it is just a fallback
14 2 my $_glogger;
15  
16 my $_counter; # to hold sub to count
17  
18 BEGIN {
19 my $x = sub {
20 2 ▶ my $start = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
21 2 ▶ return sub {$start++}};
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
22 2 $_counter = &$x(0); # used to count dbh connections
23 }
24  
25  
26 sub STORE{
27 9 ▶ my $dbh = shift;
Subroutine STORE: called CC=3 SCAR=11.2
28 9 my @args = @_;
29  
30 9 my $h = $dbh->{private_DBIx_LogAny};
31 # as we don't set private_DBIx_LogAny until the connect method sometimes
32 # $h will not be set
33 $dbh->_dbix_la_debug($h, 2, "STORE($h->{dbh_no})", @args)
34 9 ▶ if ($h && ($h->{logmask} & DBIX_LA_LOG_STORE));
Branch: 1 branch
BranchTrueFalseTotal
if $h and $h->{"logmask"} & 1024 0 9 9
Condition66%2/3
$h and $h->{"logmask"} & 1024
!ll&&!rl&&r
180
MC/DC0%0/2
$h and $h->{"logmask"} & 1024
$h $h->{"logmask"} & 1024
Truth table66%2/3
A and B
A= $hB= $h->{"logmask"} & 1024
ABresult
0X0
100
111
35  
36 9 return $dbh->SUPER::STORE(@args);
37 }
38  
39 sub get_info
40 {
41 0 ▶ my ($dbh, @args) = @_;
Subroutine get_info: not called CC=2 SCAR=17.9
Pod documented
42  
43 0 my $h = $dbh->{private_DBIx_LogAny};
44 0 my $value = $dbh->SUPER::get_info(@args);
45  
46 $dbh->_dbix_la_debug($h, 2, "get_info($h->{dbh_no})", @args, $value)
47 0 ▶ if ($h->{logmask} & DBIX_LA_LOG_INPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 1 0 0 0
48 0 return $value;
49 }
50 sub prepare {
51 5 ▶ my($dbh, @args) = @_;
Subroutine prepare: called CC=5 SCAR=16.5
Pod documented
52  
53 5 my $h = $dbh->{private_DBIx_LogAny};
54 5 my $ctr = $h->{new_stmt_no}(); # get a new unique stmt counter in this dbh
55 5 ▶ if (($h->{logmask} & (DBIX_LA_LOG_INPUT|DBIX_LA_LOG_SQL)) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::LogAny/o and not +(caller) =~ /^DBD::/o) 2 3 5
Condition50%3/6
$h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::LogAny/o and not +(caller) =~ /^DBD::/o
!ll&&!rl&&r
032
$h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::LogAny/o
!ll&&!rl&&r
005
MC/DC33%1/3
$h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::LogAny/o and not +(caller) =~ /^DBD::/o
$h->{"logmask"} & 513 not +(caller) =~ /^DBIx::LogAny/o not +(caller) =~ /^DBD::/o
Truth table50%2/4
A and not(B) and not(C)
A= $h->{"logmask"} & 513B= not +(caller) =~ /^DBIx::LogAny/oC= not +(caller) =~ /^DBD::/o
ABCresult
0XX0
10X0
1100
1111
56 (caller !~ /^DBIx::LogAny/o) &&
57 (caller !~ /^DBD::/o)) { # e.g. from selectall_arrayref
58 2 $dbh->_dbix_la_debug($h, 2, "prepare($h->{dbh_no}.$ctr)", $args[0]);
59 }
60  
61 5 my $sth = $dbh->SUPER::prepare(@args);
62 5 ▶ if ($sth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth) 5 0 5
63 5 $sth->{private_DBIx_LogAny} = $h;
64 5 $sth->{private_DBIx_st_no} = $ctr;
65 }
66  
67 5 return $sth;
68 }
69  
70 sub prepare_cached {
71 0 ▶ my($dbh, @args) = @_;
Subroutine prepare_cached: not called CC=5 SCAR=34.0
Pod documented
72  
73 0 my $h = $dbh->{private_DBIx_LogAny};
74 0 my $ctr = $h->{new_stmt_no}();
75 0 ▶ if (($h->{logmask} & (DBIX_LA_LOG_INPUT|DBIX_LA_LOG_SQL)) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::LogAny/o and not +(caller) =~ /^DBD::/o) 0 0 0
Condition0%0/6
$h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::LogAny/o and not +(caller) =~ /^DBD::/o
!ll&&!rl&&r
000
$h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::LogAny/o
!ll&&!rl&&r
000
MC/DC0%0/3
$h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::LogAny/o and not +(caller) =~ /^DBD::/o
$h->{"logmask"} & 513 not +(caller) =~ /^DBIx::LogAny/o not +(caller) =~ /^DBD::/o
Truth table0%0/4
A and not(B) and not(C)
A= $h->{"logmask"} & 513B= not +(caller) =~ /^DBIx::LogAny/oC= not +(caller) =~ /^DBD::/o
ABCresult
0XX0
10X0
1100
1111
76 (caller !~ /^DBIx::LogAny/o) &&
77 (caller !~ /^DBD::/o)) { # e.g. from selectall_arrayref
78 0 $dbh->_dbix_la_debug($h, 2,
79 "prepare_cached($h->{dbh_no}.$ctr)", $args[0]);
80 }
81  
82 0 my $sth = $dbh->SUPER::prepare_cached(@args);
83 0 ▶ if ($sth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth) 0 0 0
84 0 $sth->{private_DBIx_LogAny} = $h;
85 0 $sth->{private_DBIx_st_no} = $ctr;
86 }
87 0 return $sth;
88 }
89  
90 sub do {
91 3 ▶ my ($dbh, @args) = @_;
Subroutine do: called CC=11 SCAR=26.3
Pod documented
92 3 my $h = $dbh->{private_DBIx_LogAny};
93  
94 3 $h->{Statement} = $args[0];
95 $dbh->_dbix_la_debug($h, 2, "do($h->{dbh_no})", @args)
96 3 ▶ if ($h->{logmask} & (DBIX_LA_LOG_INPUT|DBIX_LA_LOG_SQL));
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 513 3 0 3
97  
98 3 my $affected = $dbh->SUPER::do(@args);
99  
100 3 ▶ if (!defined($affected)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $affected) { } 1 2 3
elsif (defined $affected and $affected eq '0E0' and $h->{'logmask'} & 32) { } 0 2 2
elsif ($affected ne '0E0' and $h->{'logmask'} & 1) { } 1 2 3
101 $dbh->_dbix_la_error(2, 'do error for ', @args)
102 if (($h->{logmask} & DBIX_LA_LOG_ERRCAPTURE) &&
103 1 ▶ !($h->{logmask} & DBIX_LA_LOG_INPUT)); # not already logged
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 16 and not $h->{"logmask"} & 1 0 1 1
Condition33%1/3
$h->{"logmask"} & 16 and not $h->{"logmask"} & 1
!ll&&!rl&&r
010
MC/DC0%0/2
$h->{"logmask"} & 16 and not $h->{"logmask"} & 1
$h->{"logmask"} & 16 not $h->{"logmask"} & 1
Truth table33%1/3
A and not(B)
A= $h->{"logmask"} & 16B= not $h->{"logmask"} & 1
ABresult
0X0
100
111
104 ▶ } elsif (defined($affected) && $affected eq '0E0' &&
Condition66%4/6
defined $affected and $affected eq "0E0" and $h->{"logmask"} & 32
!ll&&!rl&&r
110
defined $affected and $affected eq "0E0"
!ll&&!rl&&r
011
MC/DC0%0/3
defined $affected and $affected eq "0E0" and $h->{"logmask"} & 32
defined $affected $affected eq "0E0" $h->{"logmask"} & 32
Truth table50%2/4
A and B and C
A= defined $affectedB= $affected eq "0E0"C= $h->{"logmask"} & 32
ABCresult
0XX0
10X0
1100
1111
105 ($h->{logmask} & DBIX_LA_LOG_WARNINGS)) {
106 0 $dbh->_dbix_la_warning(2, 'no effect from ', @args);
107 ▶ } elsif (($affected ne '0E0') && ($h->{logmask} & DBIX_LA_LOG_INPUT)) {
Condition66%2/3
$affected ne "0E0" and $h->{"logmask"} & 1
!ll&&!rl&&r
101
MC/DC50%1/2
$affected ne "0E0" and $h->{"logmask"} & 1
$affected ne "0E0" $h->{"logmask"} & 1
Truth table66%2/3
A and B
A= $affected ne "0E0"B= $h->{"logmask"} & 1
ABresult
0X0
100
111
108 1 $dbh->_dbix_la_debug($h, 2, "affected($h->{dbh_no})", $affected);
109 1 ▶ $dbh->_dbix_la_debug($h, 2, "\t" . $dbh->SUPER::errstr)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $affected 0 1 1
110 if (!defined($affected));
111 }
112 3 return $affected;
113 }
114  
115 sub selectrow_array {
116 0 ▶ my ($dbh, @args) = @_;
Subroutine selectrow_array: not called CC=7 SCAR=40.3
Pod documented
117  
118 0 my $h = $dbh->{private_DBIx_LogAny};
119  
120 0 ▶ if ($h->{logmask} & (DBIX_LA_LOG_INPUT|DBIX_LA_LOG_SQL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 513) 0 0 0
121 0 ▶ if ((scalar(@args) > 0) && (ref $args[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args > 0 and ref $args[0]) { } 0 0 0
Condition0%0/3
scalar @args > 0 and ref $args[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @args > 0 and ref $args[0]
scalar @args > 0 ref $args[0]
Truth table0%0/3
A and B
A= scalar @args > 0B= ref $args[0]
ABresult
0X0
100
111
122 $dbh->_dbix_la_debug($h,
123 2,
124 "selectrow_array($h->{dbh_no}." .
125 0 $args[0]->{private_DBIx_st_no} . ")", @args);
126 } else {
127 0 $dbh->_dbix_la_debug($h, 2,
128 "selectrow_array($h->{dbh_no})", @args);
129 }
130 }
131  
132 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
133 0 my @ret = $dbh->SUPER::selectrow_array(@args);
134 $dbh->_dbix_la_debug($h, 2, "result($h->{dbh_no})", @ret)
135 0 ▶ if ($h->{logmask} & DBIX_LA_LOG_OUTPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 2 0 0 0
136 0 return @ret;
137  
138 } else {
139 0 my $ret = $dbh->SUPER::selectrow_array(@args);
140 $dbh->_dbix_la_debug($h, 2, "result($h->{dbh_no})", $ret)
141 0 ▶ if ($h->{logmask} & DBIX_LA_LOG_OUTPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 2 0 0 0
142 0 return $ret;
143 }
144 }
145  
146 sub selectrow_arrayref {
147 0 ▶ my ($dbh, @args) = @_;
Subroutine selectrow_arrayref: not called CC=5 SCAR=34.0
Pod documented
148  
149 0 my $h = $dbh->{private_DBIx_LogAny};
150  
151 0 ▶ if ($h->{logmask} & (DBIX_LA_LOG_INPUT|DBIX_LA_LOG_SQL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 513) 0 0 0
152 0 ▶ if ((scalar(@args) > 0) && (ref $args[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args > 0 and ref $args[0]) { } 0 0 0
Condition0%0/3
scalar @args > 0 and ref $args[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @args > 0 and ref $args[0]
scalar @args > 0 ref $args[0]
Truth table0%0/3
A and B
A= scalar @args > 0B= ref $args[0]
ABresult
0X0
100
111
153 $dbh->_dbix_la_debug(
154 $h, 2,
155 "selectrow_arrayref($h->{dbh_no}." .
156 0 $args[0]->{private_DBIx_st_no} . ")", @args);
157 } else {
158 0 $dbh->_dbix_la_debug(
159 $h, 2, "selectrow_arrayref($h->{dbh_no})", @args);
160 }
161 }
162  
163 0 my $ref = $dbh->SUPER::selectrow_arrayref(@args);
164 $dbh->_dbix_la_debug($h, 2, "result($h->{dbh_no})", $ref)
165 0 ▶ if ($h->{logmask} & DBIX_LA_LOG_OUTPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 2 0 0 0
166 0 return $ref;
167 }
168  
169 sub selectrow_hashref {
170 0 ▶ my ($dbh, @args) = @_;
Subroutine selectrow_hashref: not called CC=4 SCAR=30.0
Pod documented
171  
172 0 my $h = $dbh->{private_DBIx_LogAny};
173  
174 0 ▶ if ($h->{logmask} & (DBIX_LA_LOG_INPUT|DBIX_LA_LOG_SQL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 513) 0 0 0
175 0 ▶ if ((scalar(@args) > 0) && (ref $args[0])){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args > 0 and ref $args[0]) { } 0 0 0
Condition0%0/3
scalar @args > 0 and ref $args[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @args > 0 and ref $args[0]
scalar @args > 0 ref $args[0]
Truth table0%0/3
A and B
A= scalar @args > 0B= ref $args[0]
ABresult
0X0
100
111
176 $dbh->_dbix_la_debug(
177 $h, 2,
178 "selectrow_hashref($h->{dbh_no}." .
179 0 $args[0]->{private_DBIx_st_no} . ")", @args)
180 } else {
181 0 $dbh->_dbix_la_debug($h, 2,
182 "selectrow_hashref($h->{dbh_no})", @args);
183 }
184 }
185  
186 0 my $ref = $dbh->SUPER::selectrow_hashref(@args);
187 # no need to show result - fetch will do this
188 0 return $ref;
189  
190 }
191  
192 sub selectall_arrayref {
193 1 ▶ my ($dbh, @args) = @_;
Subroutine selectall_arrayref: called CC=5 SCAR=17.8
Pod documented
194  
195 1 my $h = $dbh->{private_DBIx_LogAny};
196 1 ▶ if ($h->{logmask} & (DBIX_LA_LOG_INPUT|DBIX_LA_LOG_SQL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 513) 1 0 1
197 1 ▶ if ((scalar(@args) > 0) && (ref $args[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args > 0 and ref $args[0]) { } 1 0 1
Condition33%1/3
scalar @args > 0 and ref $args[0]
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @args > 0 and ref $args[0]
scalar @args > 0 ref $args[0]
Truth table33%1/3
A and B
A= scalar @args > 0B= ref $args[0]
ABresult
0X0
100
111
198 $dbh->_dbix_la_debug(
199 $h, 2,
200 "selectall_arrayref($h->{dbh_no}." .
201 1 $args[0]->{private_DBIx_st_no} . ")", @args);
202 } else {
203 0 $dbh->_dbix_la_debug(
204 $h, 2, "selectall_arrayref($h->{dbh_no})", @args);
205 }
206 }
207  
208 1 my $ref = $dbh->SUPER::selectall_arrayref(@args);
209 $dbh->_dbix_la_debug($h, 2, "result($h->{dbh_no})", $ref)
210 1 ▶ if ($h->{logmask} & DBIX_LA_LOG_OUTPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 2 0 1 1
211 1 return $ref;
212 }
213  
214 sub selectall_hashref {
215 0 ▶ my ($dbh, @args) = @_;
Subroutine selectall_hashref: not called CC=4 SCAR=30.0
Pod documented
216  
217 0 my $h = $dbh->{private_DBIx_LogAny};
218 0 ▶ if ($h->{logmask} & (DBIX_LA_LOG_INPUT|DBIX_LA_LOG_SQL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 513) 0 0 0
219 0 ▶ if ((scalar(@args) > 0) && (ref $args[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args > 0 and ref $args[0]) { } 0 0 0
Condition0%0/3
scalar @args > 0 and ref $args[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @args > 0 and ref $args[0]
scalar @args > 0 ref $args[0]
Truth table0%0/3
A and B
A= scalar @args > 0B= ref $args[0]
ABresult
0X0
100
111
220 $dbh->_dbix_la_debug(
221 $h, 2,
222 "selectall_hashref($h->{dbh_no}." .
223 0 $args[0]->{private_DBIx_st_no} . ")", @args);
224 } else {
225 0 $dbh->_dbix_la_debug($h, 2,
226 "selectall_hashref($h->{dbh_no})", @args);
227 }
228 }
229  
230 0 my $ref = $dbh->SUPER::selectall_hashref(@args);
231 # no need to show result - fetch will do this
232 0 return $ref;
233  
234 }
235  
236 sub _make_counter {
237 1 ▶ my $start = shift;
Subroutine _make_counter: called CC=1 SCAR=0.0
238 5 ▶ return sub {$start++}
Subroutine __ANON__: called CC=1 SCAR=0.0
239 1 };
240  
241 sub connected {
242  
243 1 ▶ my ($dbh, $dsn, $user, $pass, $attr) = @_;
Subroutine connected: called CC=10 SCAR=26.2
Pod undocumented
244  
245 1 my %h = ();
246 1 $h{dbh_no} = &$_counter();
247 1 $h{new_stmt_no} = _make_counter(0); # get a new stmt count for this dbh
248  
249 # if passed a Log4perl log handle use that
250 1 ▶ if (exists($attr->{dbix_la_logger})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $attr->{'dbix_la_logger'}) { } 0 1 1
elsif (exists $attr->{'dbix_la_category'}) { } 0 1 1
251 0 $h{logger} = $attr->{dbix_la_logger};
252 } elsif (exists($attr->{dbix_la_category})) {
253 0 $h{category} = $attr->{dbix_la_category};
254 0 $h{logger} = Log::Any->get_logger(category => $h{category});
255 } else {
256 1 $h{logger} = Log::Any->get_logger(category => __PACKAGE__);
257 }
258  
259 # save log mask
260 1 ▶ $h{logmask} = $attr->{dbix_la_logmask} if (exists($attr->{dbix_la_logmask}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"dbix_la_logmask"} 0 1 1
261 # save error regexp
262 $h{err_regexp} = $attr->{dbix_la_ignore_err_regexp}
263 1 ▶ if (exists($attr->{dbix_la_ignore_err_regexp}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"dbix_la_ignore_err_regexp"} 0 1 1
264  
265 # take global log mask if non defined
266 1 ▶ $h{logmask} = $LogMask unless (exists($h{logmask}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $h{"logmask"} 1 0 1
267  
268 1 $_glogger = $h{logger};
269  
270  
271 1 $h{dbd_specific} = 0;
272 1 $h{driver} = $dbh->{Driver}->{Name};
273  
274 1 $dbh->{private_DBIx_LogAny} = \%h;
275  
276 1 $h{ll_loaded} = Module::Loaded::is_loaded('Log::Log4perl');
277 1 ▶ if ($h{ll_loaded}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h{"ll_loaded"}) 0 1 1
278 # register all our packages so Log::Log4perl skips them
279 0 Log::Log4perl->wrapper_register('DBIx::LogAny');
280 0 Log::Log4perl->wrapper_register('DBIx::LogAny::db');
281 0 Log::Log4perl->wrapper_register('DBIx::LogAny::st')
282 }
283  
284 #
285 # If capturing errors then save any error handler and set_err Handler
286 # passed to us and replace with our own.
287 #
288 1 ▶ if ($h{logmask} & DBIX_LA_LOG_ERRCAPTURE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h{"logmask"} & 16) 1 0 1
289 $h{HandleError} = $attr->{HandleError}
290 1 ▶ if (exists($attr->{HandleError}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"HandleError"} 0 1 1
291 $h{HandleSetErr} = $attr->{HandleSetErr}
292 1 ▶ if (exists($attr->{HandleSetErr}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"HandleSetErr"} 0 1 1
293 1 $dbh->{HandleError} = \&_error_handler;
294 1 $dbh->{HandleSetErr} = \&_set_err_handler;
295 }
296 1 return;
297  
298 }
299 sub clone {
300 0 ▶ my ($dbh, @args) = @_;
Subroutine clone: not called CC=2 SCAR=17.9
Pod documented
301  
302 0 my $h = $dbh->{private_DBIx_LogAny};
303 0 ▶ if ($h->{logmask} & DBIX_LA_LOG_CONNECT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 4) 0 0 0
304 0 $dbh->_dbix_la_debug($h, 2, "clone($h->{dbh_no})", @args);
305 }
306  
307 0 return $dbh->SUPER::clone(@args);
308 }
309  
310 sub disconnect {
311 1 ▶ my $dbh = shift;
Subroutine disconnect: called CC=6 SCAR=19.9
Pod documented
312  
313 1 ▶ if ($dbh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh) 1 0 1
314 1 my $h;
315 1 eval {
316 # Avoid
317 # (in cleanup) Can't call method "FETCH" on an undefined value
318 1 $h = $dbh->{private_DBIx_LogAny};
319 };
320 1 ▶ if (!$@ && $h && defined($h->{logger})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $@ and $h and defined $h->{"logger"}) 1 0 1
Condition33%2/6
not $@ and $h and defined $h->{"logger"}
!ll&&!rl&&r
001
not $@ and $h
!ll&&!rl&&r
001
MC/DC0%0/3
not $@ and $h and defined $h->{"logger"}
not $@ $h defined $h->{"logger"}
Truth table25%1/4
not(A) and B and C
A= not $@B= $hC= defined $h->{"logger"}
ABCresult
0XX0
10X0
1100
1111
321 1 ▶ if ($h->{logmask} & DBIX_LA_LOG_CONNECT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 4) 1 0 1
322 1 $dbh->_dbix_la_debug($h, 2, "disconnect($h->{dbh_no})");
323 }
324 }
325 }
326 1 return $dbh->SUPER::disconnect;
327  
328 }
329  
330 sub begin_work {
331 0 ▶ my $dbh = shift;
Subroutine begin_work: not called CC=2 SCAR=17.9
Pod documented
332 0 my $h = $dbh->{private_DBIx_LogAny};
333  
334 $dbh->_dbix_la_debug($h, 2, "start transaction($h->{dbh_no})")
335 0 ▶ if ($h->{logmask} & DBIX_LA_LOG_TXN);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 8 0 0 0
336  
337 0 return $dbh->SUPER::begin_work;
338 }
339  
340 sub rollback {
341 0 ▶ my $dbh = shift;
Subroutine rollback: not called CC=2 SCAR=17.9
Pod documented
342 0 my $h = $dbh->{private_DBIx_LogAny};
343  
344 $dbh->_dbix_la_debug($h, 2, "roll back($h->{dbh_no})")
345 0 ▶ if ($h->{logmask} & DBIX_LA_LOG_TXN);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 8 0 0 0
346  
347 0 return $dbh->SUPER::rollback;
348 }
349  
350 sub commit {
351 0 ▶ my $dbh = shift;
Subroutine commit: not called CC=2 SCAR=17.9
Pod documented
352  
353 0 my $h = $dbh->{private_DBIx_LogAny};
354 $dbh->_dbix_la_debug($h, 2, "commit($h->{dbh_no})")
355 0 ▶ if ($h->{logmask} & DBIX_LA_LOG_TXN);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 8 0 0 0
356  
357 0 return $dbh->SUPER::commit;
358 }
359  
360 sub last_insert_id {
361 0 ▶ my ($dbh, @args) = @_;
Subroutine last_insert_id: not called CC=3 SCAR=24.8
Pod documented
362 0 my $h = $dbh->{private_DBIx_LogAny};
363  
364 $dbh->_dbix_la_debug(
365 $h, 2, Data::Dumper->Dump([\@args], ["last_insert_id($h->{dbh_no})"]))
366 0 ▶ if ($h->{logmask} & DBIX_LA_LOG_INPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 1 0 0 0
367  
368 0 my $ret = $dbh->SUPER::last_insert_id(@args);
369 $dbh->_dbix_la_debug($h, 2, "\t" . DBI::neat($ret))
370 0 ▶ if ($h->{logmask} & DBIX_LA_LOG_INPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 1 0 0 0
371 0 return $ret;
372 }
373  
374  
375 #
376 # Error handler to capture errors and log them
377 # Whatever, errors are passed on.
378 # if the user of DBIx::LogAny passed in an error handler that is called
379 # before returning.
380 #
381 sub _error_handler {
382 1 ▶ my ($msg, $handle, $method_ret) = @_;
Subroutine _error_handler: called CC=39 SCAR=56.3
383  
384 1 my $dbh = $handle;
385 1 my $lh;
386 1 my $h = $handle->{private_DBIx_LogAny};
387 1 my $out = '';
388  
389 1 $lh = $_glogger;
390 1 ▶ $lh = $h->{logger} if ($h && exists($h->{logger}));
Branch: 1 branch
BranchTrueFalseTotal
if $h and exists $h->{"logger"} 1 0 1
Condition33%1/3
$h and exists $h->{"logger"}
!ll&&!rl&&r
001
MC/DC0%0/2
$h and exists $h->{"logger"}
$h exists $h->{"logger"}
Truth table33%1/3
A and B
A= $hB= exists $h->{"logger"}
ABresult
0X0
100
111
391 1 ▶ return 0 if (!$lh);
Branch: 1 branch
BranchTrueFalseTotal
unless $lh 0 1 1
392  
393 1 ▶ if (!$lh->is_fatal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lh->is_fatal) 0 1 1
394 0 goto FINISH;
395 }
396  
397 1 ▶ if ($h && exists($h->{err_regexp})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h and exists $h->{"err_regexp"}) 0 1 1
Condition33%1/3
$h and exists $h->{"err_regexp"}
!ll&&!rl&&r
010
MC/DC0%0/2
$h and exists $h->{"err_regexp"}
$h exists $h->{"err_regexp"}
Truth table33%1/3
A and B
A= $hB= exists $h->{"err_regexp"}
ABresult
0X0
100
111
398 0 ▶ if ($dbh->err =~ $h->{err_regexp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err =~ /$h->{"err_regexp"}/) 0 0 0
399 0 goto FINISH;
400 }
401 }
402 # start with error message, state and err
403 1 $out .= ' ' . '=' x 60 . "\n $msg\n";
404 1 $out .= "err() = " . $handle->err . "\n";
405 1 $out .= "state() = " . $handle->state . "\n";
406  
407 1 ▶ if ($DBI::lasth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBI::lasth) 1 0 1
408 $out .= " lasth type: $DBI::lasth->{Type}\n"
409 1 ▶ if ($DBI::lasth->{Type});
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::lasth->{"Type"} 0 1 1
410 $out .= " lasth Statement ($DBI::lasth):\n " .
411 "$DBI::lasth->{Statement}\n"
412 1 ▶ if ($DBI::lasth->{Statement});
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::lasth->{"Statement"} 1 0 1
413 }
414 # get db handle if we have an st
415 1 my $type = $handle->{Type};
416 1 my $sql;
417 1 ▶ if ($type eq 'st') { # given statement handle
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'st') { } 0 1 1
418 0 $dbh = $handle->{Database};
419 0 $sql = $handle->{Statement};
420 } else {
421 # given db handle
422 # We've got other stmts under this db but we'll deal with those later
423 1 $sql = 'Possible SQL: ';
424 1 ▶ $sql .= "/$h->{Statement}/" if (exists($h->{Statement}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $h->{"Statement"} 1 0 1
425 $sql .= "/$dbh->{Statement}/"
426 if ($dbh->{Statement} &&
427 (exists($h->{Statement}) &&
428 1 ▶ ($dbh->{Statement} ne $h->{Statement})));
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->{"Statement"} and (exists $h->{"Statement"} and $dbh->{"Statement"} ne $h->{"Statement"}) 0 1 1
Condition33%2/6
$dbh->{"Statement"} and (exists $h->{"Statement"} and $dbh->{"Statement"} ne $h->{"Statement"})
!ll&&!rl&&r
010
exists $h->{"Statement"} and $dbh->{"Statement"} ne $h->{"Statement"}
!ll&&!rl&&r
010
MC/DC0%0/3
$dbh->{"Statement"} and (exists $h->{"Statement"} and $dbh->{"Statement"} ne $h->{"Statement"})
$dbh->{"Statement"} exists $h->{"Statement"} $dbh->{"Statement"} ne $h->{"Statement"}
Truth table25%1/4
A and B and C
A= $dbh->{"Statement"}B= exists $h->{"Statement"}C= $dbh->{"Statement"} ne $h->{"Statement"}
ABCresult
0XX0
10X0
1100
1111
429 }
430  
431 1 ▶ my $dbname = exists($dbh->{Name}) ? $dbh->{Name} : "";
Branch: 1 branch
BranchTrueFalseTotal
exists $dbh->{'Name'} ? : 1 0 1
432 1 ▶ my $username = exists($dbh->{Username}) ? $dbh->{Username} : "";
Branch: 1 branch
BranchTrueFalseTotal
exists $dbh->{'Username'} ? : 1 0 1
433 1 $out .= " DB: $dbname, Username: $username\n";
434 1 $out .= " handle type: $type\n SQL: " . DBI::neat($sql) . "\n";
435 $out .= ' db Kids=' . $dbh->{Kids} .
436 1 ', ActiveKids=' . $dbh->{ActiveKids} . "\n";
437 1 ▶ $out .= " DB errstr: " . $handle->errstr . "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $handle->errstr and $handle->errstr ne $msg 1 0 1
Condition33%1/3
$handle->errstr and $handle->errstr ne $msg
!ll&&!rl&&r
001
MC/DC0%0/2
$handle->errstr and $handle->errstr ne $msg
$handle->errstr $handle->errstr ne $msg
Truth table33%1/3
A and B
A= $handle->errstrB= $handle->errstr ne $msg
ABresult
0X0
100
111
438 if ($handle->errstr && ($handle->errstr ne $msg));
439  
440 1 ▶ if (exists($h->{ParamValues}) && $h->{ParamValues}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h->{"ParamValues"} and $h->{"ParamValues"}) 0 1 1
Condition33%1/3
exists $h->{"ParamValues"} and $h->{"ParamValues"}
!ll&&!rl&&r
100
MC/DC0%0/2
exists $h->{"ParamValues"} and $h->{"ParamValues"}
exists $h->{"ParamValues"} $h->{"ParamValues"}
Truth table33%1/3
A and B
A= exists $h->{"ParamValues"}B= $h->{"ParamValues"}
ABresult
0X0
100
111
441 0 $out .= " ParamValues captured in HandleSetErr:\n ";
442 0 foreach (sort keys %{$h->{ParamValues}}) {
443 0 $out .= "$_=" . DBI::neat($h->{ParamValues}->{$_}) . ",";
444 }
445 0 $out .= "\n";
446 }
447 1 ▶ if ($type eq 'st') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "st") 0 1 1
448 0 my $str = "";
449 0 ▶ if ($handle->{ParamValues}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handle->{"ParamValues"}) 0 0 0
450 0 foreach (sort keys %{$handle->{ParamValues}}) {
451 0 $str .= "$_=" . DBI::neat($handle->{ParamValues}->{$_}) . ",";
452 }
453 }
454 0 $out .= " ParamValues: $str\n";
455 $out .= " " .
456 Data::Dumper->Dump([$handle->{ParamArrays}], ['ParamArrays'])
457 0 ▶ if ($handle->{ParamArrays});
Branch: 1 branch
BranchTrueFalseTotal
if $handle->{"ParamArrays"} 0 0 0
458 }
459 1 my @substmts;
460 # get list of statements under the db
461 1 push @substmts, $_ for (grep { defined } @{$dbh->{ChildHandles}});
462 1 $out .= " " . scalar(@substmts) . " sub statements:\n";
463 1 ▶ if (scalar(@substmts)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @substmts) 0 1 1
464 0 foreach my $stmt (@substmts) {
465 0 $out .= " stmt($stmt):\n";
466 $out .= ' SQL(' . $stmt->{Statement} . ")\n "
467 if ($stmt->{Statement} &&
468 (exists($h->{Statement}) &&
469 0 ▶ ($h->{Statement} ne $stmt->{Statement})));
Branch: 1 branch
BranchTrueFalseTotal
if $stmt->{"Statement"} and (exists $h->{"Statement"} and $h->{"Statement"} ne $stmt->{"Statement"}) 0 0 0
Condition0%0/6
$stmt->{"Statement"} and (exists $h->{"Statement"} and $h->{"Statement"} ne $stmt->{"Statement"})
!ll&&!rl&&r
000
exists $h->{"Statement"} and $h->{"Statement"} ne $stmt->{"Statement"}
!ll&&!rl&&r
000
MC/DC0%0/3
$stmt->{"Statement"} and (exists $h->{"Statement"} and $h->{"Statement"} ne $stmt->{"Statement"})
$stmt->{"Statement"} exists $h->{"Statement"} $h->{"Statement"} ne $stmt->{"Statement"}
Truth table0%0/4
A and B and C
A= $stmt->{"Statement"}B= exists $h->{"Statement"}C= $h->{"Statement"} ne $stmt->{"Statement"}
ABCresult
0XX0
10X0
1100
1111
470 0 ▶ if (exists($stmt->{ParamValues}) && $stmt->{ParamValues}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $stmt->{"ParamValues"} and $stmt->{"ParamValues"}) 0 0 0
Condition0%0/3
exists $stmt->{"ParamValues"} and $stmt->{"ParamValues"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $stmt->{"ParamValues"} and $stmt->{"ParamValues"}
exists $stmt->{"ParamValues"} $stmt->{"ParamValues"}
Truth table0%0/3
A and B
A= exists $stmt->{"ParamValues"}B= $stmt->{"ParamValues"}
ABresult
0X0
100
111
471 0 $out .= ' Params(';
472 0 foreach (sort keys %{$stmt->{ParamValues}}) {
473 0 $out .= "$_=" . DBI::neat($stmt->{ParamValues}->{$_}) . ",";
474 }
475 0 $out .= ")\n";
476 }
477 }
478 }
479  
480 1 ▶ if (exists($dbh->{Callbacks})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dbh->{"Callbacks"}) 0 1 1
481 $out .= " Callbacks exist for " .
482 0 join(",", keys(%{$dbh->{Callbacks}})) . "\n";
483 }
484 1 local $Carp::MaxArgLen = 256;
485 1 $out .= " " .Carp::longmess("DBI error trap");
486 1 $out .= " " . "=" x 60 . "\n";
487  
488 1 $lh->fatal($out);
489  
490 FINISH:
491 1 ▶ if ($h && exists($h->{ErrorHandler})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h and exists $h->{'ErrorHandler'}) { } 0 1 1
Condition33%1/3
$h and exists $h->{"ErrorHandler"}
!ll&&!rl&&r
010
MC/DC0%0/2
$h and exists $h->{"ErrorHandler"}
$h exists $h->{"ErrorHandler"}
Truth table33%1/3
A and B
A= $hB= exists $h->{"ErrorHandler"}
ABresult
0X0
100
111
492 0 return $h->{ErrorHandler}($msg, $handle, $method_ret);
493 } else {
494 1 return 0; # pass error on
495 }
496 }
497  
498 #
499 # set_err handler so we can capture ParamValues before a statement
500 # is destroyed.
501 # If the use of DBIx::LogAny passed in an error handler that is
502 # called before returning.
503 #
504 sub _set_err_handler {
505 1 ▶ my ($handle, $err, $errstr, $state, $method) = @_;
Subroutine _set_err_handler: called CC=4 SCAR=14.5
506  
507 # Capture ParamValues
508 1 ▶ if ($handle) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handle) 1 0 1
509 1 my $h = $handle->{private_DBIx_LogAny};
510 $h->{ParamValues} = $handle->{ParamValues}
511 1 ▶ if (exists($handle->{ParamValues}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $handle->{"ParamValues"} 0 1 1
512 1 ▶ return $h->{HandleSetErr}(@_) if (exists($h->{HandleSetErr}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $h->{"HandleSetErr"} 0 1 1
513 }
514 1 return 0;
515 }
516  
517  
518 2 1;
↑ Summary LogAny/st.pm »