Log4perl/db.pm

filter: Statementstmt 10.5% 28 / 266 Branchbran 0.0% 0 / 150 Conditioncond 0.0% 0 / 85 MC/DCmcdc 0.0% 0 / 50 Subroutinesub 27.2% 9 / 33 Podpod 93.7% 15 / 16 totaltotal 8.6% 52 / 600 CC 109 SCAR 61.2
CC
109
Cov
6%
_error_handler
1482.0
connected
271.4
do
132.0
CRAP 454.0
↑ Summary Log4perl/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 Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package DBIx::Log4perl::db;
9 2 @DBIx::Log4perl::db::ISA = qw(DBI::db DBIx::Log4perl);
10 2 ▶use DBIx::Log4perl::Constants qw (:masks $LogMask);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # $_glogger is not relied upon - it is just a fallback
13 2 my $_glogger;
14  
15 my $_counter; # to hold sub to count
16  
17 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.1
18 2 ▶ my $x = sub {
Subroutine __ANON__: called CC=1 SCAR=0.2
19 2 my $start = shift;
20 0 ▶ return sub {$start++}};
Subroutine __ANON__: not called CC=1 SCAR=0.4
21 2 $_counter = &$x(0); # used to count dbh connections
22 }
23  
24  
25 0 ▶sub STORE{
Subroutine STORE: not called CC=3 SCAR=24.8
26 0 my $dbh = shift;
27 0 my @args = @_;
28  
29 0 my $h = $dbh->{private_DBIx_Log4perl};
30 # as we don't set private_DBIx_Log4perl until the connect method sometimes
31 # $h will not be set
32 $dbh->_dbix_l4p_debug($h, 2, "STORE($h->{dbh_no})", @args)
33 0 ▶ if ($h && ($h->{logmask} & DBIX_L4P_LOG_INPUT));
Branch: 1 branch
BranchTrueFalseTotal
if $h and $h->{"logmask"} & 1 0 0 0
Condition0%0/3
$h and $h->{"logmask"} & 1
!ll&&!rl&&r
000
MC/DC0%0/2
$h and $h->{"logmask"} & 1
$h $h->{"logmask"} & 1
Truth table0%0/3
A and B
A= $hB= $h->{"logmask"} & 1
ABresult
0X0
100
111
34  
35  
36 0 return $dbh->SUPER::STORE(@args);
37 }
38  
39 sub get_info
40 0 ▶{
Subroutine get_info: not called CC=2 SCAR=17.9
Pod documented
41 0 my ($dbh, @args) = @_;
42  
43 0 my $h = $dbh->{private_DBIx_Log4perl};
44 0 my $value = $dbh->SUPER::get_info(@args);
45  
46 $dbh->_dbix_l4p_debug($h, 2, "get_info($h->{dbh_no})", @args, $value)
47 0 ▶ if ($h->{logmask} & DBIX_L4P_LOG_INPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 1 0 0 0
48 0 return $value;
49 }
50 0 ▶sub prepare {
Subroutine prepare: not called CC=5 SCAR=34.0
Pod documented
51 0 my($dbh, @args) = @_;
52  
53 0 my $h = $dbh->{private_DBIx_Log4perl};
54 0 my $ctr = $h->{new_stmt_no}(); # get a new unique stmt counter in this dbh
55 0 ▶ if (($h->{logmask} & (DBIX_L4P_LOG_INPUT|DBIX_L4P_LOG_SQL)) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::Log4perl/o and not +(caller) =~ /^DBD::/o) 0 0 0
Condition0%0/6
$h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::Log4perl/o and not +(caller) =~ /^DBD::/o
!ll&&!rl&&r
000
$h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::Log4perl/o
!ll&&!rl&&r
000
MC/DC0%0/3
$h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::Log4perl/o and not +(caller) =~ /^DBD::/o
$h->{"logmask"} & 513 not +(caller) =~ /^DBIx::Log4perl/o not +(caller) =~ /^DBD::/o
Truth table0%0/4
A and not(B) and not(C)
A= $h->{"logmask"} & 513B= not +(caller) =~ /^DBIx::Log4perl/oC= not +(caller) =~ /^DBD::/o
ABCresult
0XX0
10X0
1100
1111
56 (caller !~ /^DBIx::Log4perl/o) &&
57 (caller !~ /^DBD::/o)) { # e.g. from selectall_arrayref
58 0 $dbh->_dbix_l4p_debug($h, 2, "prepare($h->{dbh_no}.$ctr)", $args[0]);
59 }
60  
61 0 my $sth = $dbh->SUPER::prepare(@args);
62 0 ▶ if ($sth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth) 0 0 0
63 0 $sth->{private_DBIx_Log4perl} = $h;
64 0 $sth->{private_DBIx_st_no} = $ctr;
65 }
66  
67 0 return $sth;
68 }
69  
70 0 ▶sub prepare_cached {
Subroutine prepare_cached: not called CC=5 SCAR=34.0
Pod documented
71 0 my($dbh, @args) = @_;
72  
73 0 my $h = $dbh->{private_DBIx_Log4perl};
74 0 my $ctr = $h->{new_stmt_no}();
75 0 ▶ if (($h->{logmask} & (DBIX_L4P_LOG_INPUT|DBIX_L4P_LOG_SQL)) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::Log4perl/o and not +(caller) =~ /^DBD::/o) 0 0 0
Condition0%0/6
$h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::Log4perl/o and not +(caller) =~ /^DBD::/o
!ll&&!rl&&r
000
$h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::Log4perl/o
!ll&&!rl&&r
000
MC/DC0%0/3
$h->{"logmask"} & 513 and not +(caller) =~ /^DBIx::Log4perl/o and not +(caller) =~ /^DBD::/o
$h->{"logmask"} & 513 not +(caller) =~ /^DBIx::Log4perl/o not +(caller) =~ /^DBD::/o
Truth table0%0/4
A and not(B) and not(C)
A= $h->{"logmask"} & 513B= not +(caller) =~ /^DBIx::Log4perl/oC= not +(caller) =~ /^DBD::/o
ABCresult
0XX0
10X0
1100
1111
76 (caller !~ /^DBIx::Log4perl/o) &&
77 (caller !~ /^DBD::/o)) { # e.g. from selectall_arrayref
78 0 $dbh->_dbix_l4p_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_Log4perl} = $h;
85 0 $sth->{private_DBIx_st_no} = $ctr;
86 }
87 0 return $sth;
88 }
89  
90 0 ▶sub do {
Subroutine do: not called CC=11 SCAR=48.8
Pod documented
91 0 my ($dbh, @args) = @_;
92 0 my $h = $dbh->{private_DBIx_Log4perl};
93  
94 0 $h->{Statement} = $args[0];
95 $dbh->_dbix_l4p_debug($h, 2, "do($h->{dbh_no})", @args)
96 0 ▶ if ($h->{logmask} & (DBIX_L4P_LOG_INPUT|DBIX_L4P_LOG_SQL));
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 513 0 0 0
97  
98 0 my $affected = $dbh->SUPER::do(@args);
99  
100 0 ▶ if (!defined($affected)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $affected) { } 0 0 0
elsif (defined $affected and $affected eq '0E0' and $h->{'logmask'} & 32) { } 0 0 0
elsif ($affected ne '0E0' and $h->{'logmask'} & 1) { } 0 0 0
101 $dbh->_dbix_l4p_error(2, 'do error for ', @args)
102 if (($h->{logmask} & DBIX_L4P_LOG_ERRCAPTURE) &&
103 0 ▶ !($h->{logmask} & DBIX_L4P_LOG_INPUT)); # not already logged
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 16 and not $h->{"logmask"} & 1 0 0 0
Condition0%0/3
$h->{"logmask"} & 16 and not $h->{"logmask"} & 1
!ll&&!rl&&r
000
MC/DC0%0/2
$h->{"logmask"} & 16 and not $h->{"logmask"} & 1
$h->{"logmask"} & 16 not $h->{"logmask"} & 1
Truth table0%0/3
A and not(B)
A= $h->{"logmask"} & 16B= not $h->{"logmask"} & 1
ABresult
0X0
100
111
104 ▶ } elsif (defined($affected) && $affected eq '0E0' &&
Condition0%0/6
defined $affected and $affected eq "0E0" and $h->{"logmask"} & 32
!ll&&!rl&&r
000
defined $affected and $affected eq "0E0"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $affected and $affected eq "0E0" and $h->{"logmask"} & 32
defined $affected $affected eq "0E0" $h->{"logmask"} & 32
Truth table0%0/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_L4P_LOG_WARNINGS)) {
106 0 $dbh->_dbix_l4p_warning(2, 'no effect from ', @args);
107 ▶ } elsif (($affected ne '0E0') && ($h->{logmask} & DBIX_L4P_LOG_INPUT)) {
Condition0%0/3
$affected ne "0E0" and $h->{"logmask"} & 1
!ll&&!rl&&r
000
MC/DC0%0/2
$affected ne "0E0" and $h->{"logmask"} & 1
$affected ne "0E0" $h->{"logmask"} & 1
Truth table0%0/3
A and B
A= $affected ne "0E0"B= $h->{"logmask"} & 1
ABresult
0X0
100
111
108 0 $dbh->_dbix_l4p_debug($h, 2, "affected($h->{dbh_no})", $affected);
109 0 ▶ $dbh->_dbix_l4p_debug($h, 2, "\t" . $dbh->SUPER::errstr)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $affected 0 0 0
110 if (!defined($affected));
111 }
112 0 return $affected;
113 }
114  
115 0 ▶sub selectrow_array {
Subroutine selectrow_array: not called CC=7 SCAR=40.3
Pod documented
116 0 my ($dbh, @args) = @_;
117  
118 0 my $h = $dbh->{private_DBIx_Log4perl};
119  
120 0 ▶ if ($h->{logmask} & (DBIX_L4P_LOG_INPUT|DBIX_L4P_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_l4p_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_l4p_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_l4p_debug($h, 2, "result($h->{dbh_no})", @ret)
135 0 ▶ if ($h->{logmask} & DBIX_L4P_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_l4p_debug($h, 2, "result($h->{dbh_no})", $ret)
141 0 ▶ if ($h->{logmask} & DBIX_L4P_LOG_OUTPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 2 0 0 0
142 0 return $ret;
143 }
144 }
145  
146 0 ▶sub selectrow_arrayref {
Subroutine selectrow_arrayref: not called CC=5 SCAR=34.0
Pod documented
147 0 my ($dbh, @args) = @_;
148  
149 0 my $h = $dbh->{private_DBIx_Log4perl};
150  
151 0 ▶ if ($h->{logmask} & (DBIX_L4P_LOG_INPUT|DBIX_L4P_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_l4p_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_l4p_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_l4p_debug($h, 2, "result($h->{dbh_no})", $ref)
165 0 ▶ if ($h->{logmask} & DBIX_L4P_LOG_OUTPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 2 0 0 0
166 0 return $ref;
167 }
168  
169 0 ▶sub selectrow_hashref {
Subroutine selectrow_hashref: not called CC=4 SCAR=30.0
Pod documented
170 0 my ($dbh, @args) = @_;
171  
172 0 my $h = $dbh->{private_DBIx_Log4perl};
173  
174 0 ▶ if ($h->{logmask} & (DBIX_L4P_LOG_INPUT|DBIX_L4P_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_l4p_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_l4p_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 0 ▶sub selectall_arrayref {
Subroutine selectall_arrayref: not called CC=5 SCAR=34.0
Pod documented
193 0 my ($dbh, @args) = @_;
194  
195 0 my $h = $dbh->{private_DBIx_Log4perl};
196 0 ▶ if ($h->{logmask} & (DBIX_L4P_LOG_INPUT|DBIX_L4P_LOG_SQL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 513) 0 0 0
197 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
198 $dbh->_dbix_l4p_debug(
199 $h, 2,
200 "selectall_arrayref($h->{dbh_no}." .
201 0 $args[0]->{private_DBIx_st_no} . ")", @args);
202 } else {
203 0 $dbh->_dbix_l4p_debug(
204 $h, 2, "selectall_arrayref($h->{dbh_no})", @args);
205 }
206 }
207  
208 0 my $ref = $dbh->SUPER::selectall_arrayref(@args);
209 $dbh->_dbix_l4p_debug($h, 2, "result($h->{dbh_no})", $ref)
210 0 ▶ if ($h->{logmask} & DBIX_L4P_LOG_OUTPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 2 0 0 0
211 0 return $ref;
212 }
213  
214 0 ▶sub selectall_hashref {
Subroutine selectall_hashref: not called CC=4 SCAR=30.0
Pod documented
215 0 my ($dbh, @args) = @_;
216  
217 0 my $h = $dbh->{private_DBIx_Log4perl};
218 0 ▶ if ($h->{logmask} & (DBIX_L4P_LOG_INPUT|DBIX_L4P_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_l4p_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_l4p_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 0 ▶sub _make_counter {
Subroutine _make_counter: not called CC=1 SCAR=6.9
237 0 my $start = shift;
238 0 ▶ return sub {$start++}
Subroutine __ANON__: not called CC=1 SCAR=6.9
239 0 };
240  
241 0 ▶sub connected {
Subroutine connected: not called CC=17 SCAR=56.0
Pod undocumented
242  
243 0 my ($dbh, $dsn, $user, $pass, $attr) = @_;
244  
245 0 my %h = ();
246 0 $h{dbh_no} = &$_counter();
247 0 $h{new_stmt_no} = _make_counter(0); # get a new stmt count for this dbh
248  
249 0 ▶ if ($attr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr) 0 0 0
250 # check we have not got dbix_l4p_init without dbix_l4p_log or vice versa
251 my ($a, $b) = (exists($attr->{dbix_l4p_init}),
252 0 exists($attr->{dbix_l4p_class}));
253 0 ▶ croak ('dbix_l4p_init specified without dbix_l4p_class or vice versa')
Branch: 1 branch
BranchTrueFalseTotal
if $a xor $b 0 0 0
Condition0%0/4
$a xor $b
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
$a xor $b
$a $b
Truth table0%0/4
A xor B
A= $aB= $b
ABresult
110
101
011
000
254 if (($a xor $b));
255 # if passed a Log4perl log handle use that
256 0 ▶ if (exists($attr->{dbix_l4p_logger})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $attr->{'dbix_l4p_logger'}) { } 0 0 0
elsif ($a and $b) { } 0 0 0
257 0 $h{logger} = $attr->{dbix_l4p_logger};
258 ▶ } elsif ($a && $b) {
Condition0%0/3
$a and $b
!ll&&!rl&&r
000
MC/DC0%0/2
$a and $b
$a $b
Truth table0%0/3
A and B
A= $aB= $b
ABresult
0X0
100
111
259 0 Log::Log4perl->init($attr->{dbix_l4p_init});
260 0 $h{logger} = Log::Log4perl->get_logger($attr->{dbix_l4p_class});
261 0 $h{init} = $attr->{dbix_l4p_init};
262 0 $h{class} = $attr->{dbix_l4p_class};
263 } else {
264 0 $h{logger} = Log::Log4perl->get_logger('DBIx::Log4perl');
265 }
266 # save log mask
267 $h{logmask} = $attr->{dbix_l4p_logmask}
268 0 ▶ if (exists($attr->{dbix_l4p_logmask}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"dbix_l4p_logmask"} 0 0 0
269 # save error regexp
270 $h{err_regexp} = $attr->{dbix_l4p_ignore_err_regexp}
271 0 ▶ if (exists($attr->{dbix_l4p_ignore_err_regexp}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"dbix_l4p_ignore_err_regexp"} 0 0 0
272 # remove our attrs from connection attrs
273 #delete $attr->{dbix_l4p_init};
274 #delete $attr->{dbix_l4p_class};
275 #delete $attr->{dbix_l4p_logger};
276 #delete $attr->{dbix_l4p_logmask};
277 #delete $attr->{dbix_l4p_ignore_err_regexp};
278 }
279 # take global log mask if non defined
280 0 ▶ $h{logmask} = $LogMask unless (exists($h{logmask}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $h{"logmask"} 0 0 0
281  
282 $h{logger} = Log::Log4perl->get_logger('DBIx::Log4perl')
283 0 ▶ unless (exists($h{logger}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $h{"logger"} 0 0 0
284 0 $_glogger = $h{logger};
285  
286 # make sure you don't change the depth before calling get_logger:
287 0 local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 4;
288  
289 0 $h{dbd_specific} = 0;
290 0 $h{driver} = $dbh->{Driver}->{Name};
291  
292 0 $dbh->{private_DBIx_Log4perl} = \%h;
293  
294 0 ▶ if ($h{logmask} & DBIX_L4P_LOG_CONNECT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h{"logmask"} & 4) 0 0 0
295 0 local $Data::Dumper::Indent = 0;
296 $h{logger}->debug(
297 0 ▶ "connect($h{dbh_no}): " .
Branch: 2 branches
BranchTrueFalseTotal
defined $dsn ? : 0 0 0
defined $user ? : 0 0 0
298 (defined($dsn) ? $dsn : '') . ', ' .
299 (defined($user) ? $user : '') . ', ' .
300 Data::Dumper->Dump([$attr], [qw(attr)]));
301 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
302 0 my $v = "DBD::" . $dbh->{Driver}->{Name} . "::VERSION";
303 $h{logger}->info("DBI: " . $DBI::VERSION,
304 ", DBIx::Log4perl: " . $DBIx::Log4perl::VERSION .
305 0 ", Driver: " . $h{driver} . "(" .
306 $$v . ")");
307 }
308  
309 #
310 # If capturing errors then save any error handler and set_err Handler
311 # passed to us and replace with our own.
312 #
313 0 ▶ if ($h{logmask} & DBIX_L4P_LOG_ERRCAPTURE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h{"logmask"} & 16) 0 0 0
314 $h{HandleError} = $attr->{HandleError}
315 0 ▶ if (exists($attr->{HandleError}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"HandleError"} 0 0 0
316 $h{HandleSetErr} = $attr->{HandleSetErr}
317 0 ▶ if (exists($attr->{HandleSetErr}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"HandleSetErr"} 0 0 0
318 0 $dbh->{HandleError} = \&_error_handler;
319 0 $dbh->{HandleSetErr} = \&_set_err_handler;
320 }
321 0 return;
322  
323 }
324 0 ▶sub clone {
Subroutine clone: not called CC=2 SCAR=17.9
Pod documented
325 0 my ($dbh, @args) = @_;
326  
327 0 my $h = $dbh->{private_DBIx_Log4perl};
328 0 ▶ if ($h->{logmask} & DBIX_L4P_LOG_CONNECT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 4) 0 0 0
329 0 $dbh->_dbix_l4p_debug($h, 2, "clone($h->{dbh_no})", @args);
330 }
331  
332 0 return $dbh->SUPER::clone(@args);
333 }
334  
335 0 ▶sub disconnect {
Subroutine disconnect: not called CC=6 SCAR=37.4
Pod documented
336 0 my $dbh = shift;
337  
338 0 ▶ if ($dbh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh) 0 0 0
339 0 my $h;
340 0 eval {
341 # Avoid
342 # (in cleanup) Can't call method "FETCH" on an undefined value
343 0 $h = $dbh->{private_DBIx_Log4perl};
344 };
345 0 ▶ if (!$@ && $h && defined($h->{logger})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $@ and $h and defined $h->{"logger"}) 0 0 0
Condition0%0/6
not $@ and $h and defined $h->{"logger"}
!ll&&!rl&&r
000
not $@ and $h
!ll&&!rl&&r
000
MC/DC0%0/3
not $@ and $h and defined $h->{"logger"}
not $@ $h defined $h->{"logger"}
Truth table0%0/4
not(A) and B and C
A= not $@B= $hC= defined $h->{"logger"}
ABCresult
0XX0
10X0
1100
1111
346 0 ▶ if ($h->{logmask} & DBIX_L4P_LOG_CONNECT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 4) 0 0 0
347 0 local $Log::Log4perl::caller_depth =
348 $Log::Log4perl::caller_depth + 2;
349 0 $dbh->_dbix_l4p_debug($h, 2, "disconnect($h->{dbh_no})");
350 }
351 }
352 }
353 0 return $dbh->SUPER::disconnect;
354  
355 }
356  
357 0 ▶sub begin_work {
Subroutine begin_work: not called CC=2 SCAR=17.9
Pod documented
358 0 my $dbh = shift;
359 0 my $h = $dbh->{private_DBIx_Log4perl};
360  
361 $dbh->_dbix_l4p_debug($h, 2, "start transaction($h->{dbh_no})")
362 0 ▶ if ($h->{logmask} & DBIX_L4P_LOG_TXN);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 8 0 0 0
363  
364 0 return $dbh->SUPER::begin_work;
365 }
366  
367 0 ▶sub rollback {
Subroutine rollback: not called CC=2 SCAR=17.9
Pod documented
368 0 my $dbh = shift;
369 0 my $h = $dbh->{private_DBIx_Log4perl};
370  
371 $dbh->_dbix_l4p_debug($h, 2, "roll back($h->{dbh_no})")
372 0 ▶ if ($h->{logmask} & DBIX_L4P_LOG_TXN);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 8 0 0 0
373  
374 0 return $dbh->SUPER::rollback;
375 }
376  
377 0 ▶sub commit {
Subroutine commit: not called CC=2 SCAR=17.9
Pod documented
378 0 my $dbh = shift;
379  
380 0 my $h = $dbh->{private_DBIx_Log4perl};
381 $dbh->_dbix_l4p_debug($h, 2, "commit($h->{dbh_no})")
382 0 ▶ if ($h->{logmask} & DBIX_L4P_LOG_TXN);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 8 0 0 0
383  
384 0 return $dbh->SUPER::commit;
385 }
386  
387 0 ▶sub last_insert_id {
Subroutine last_insert_id: not called CC=3 SCAR=24.8
Pod documented
388 0 my ($dbh, @args) = @_;
389 0 my $h = $dbh->{private_DBIx_Log4perl};
390  
391 $dbh->_dbix_l4p_debug($h, 2,
392 0 ▶ sub {Data::Dumper->Dump([\@args], ["last_insert_id($h->{dbh_no})"])})
Subroutine __ANON__: not called CC=1 SCAR=6.9
393 0 ▶ if ($h->{logmask} & DBIX_L4P_LOG_INPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 1 0 0 0
394  
395 0 my $ret = $dbh->SUPER::last_insert_id(@args);
396 0 ▶ $dbh->_dbix_l4p_debug($h, 2, sub {"\t" . DBI::neat($ret)})
Subroutine __ANON__: not called CC=1 SCAR=6.9
397 0 ▶ if ($h->{logmask} & DBIX_L4P_LOG_INPUT);
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logmask"} & 1 0 0 0
398 0 return $ret;
399 }
400  
401  
402 #
403 # Error handler to capture errors and log them
404 # Whatever, errors are passed on.
405 # if the user of DBIx::Log4perl passed in an error handler that is called
406 # before returning.
407 #
408 0 ▶sub _error_handler {
Subroutine _error_handler: not called CC=38 SCAR=73.0
409 0 my ($msg, $handle, $method_ret) = @_;
410  
411 0 local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
412  
413 0 my $dbh = $handle;
414 0 my $lh;
415 0 my $h = $handle->{private_DBIx_Log4perl};
416 0 my $out = '';
417  
418 0 $lh = $_glogger;
419 0 ▶ $lh = $h->{logger} if ($h && exists($h->{logger}));
Branch: 1 branch
BranchTrueFalseTotal
if $h and exists $h->{"logger"} 0 0 0
Condition0%0/3
$h and exists $h->{"logger"}
!ll&&!rl&&r
000
MC/DC0%0/2
$h and exists $h->{"logger"}
$h exists $h->{"logger"}
Truth table0%0/3
A and B
A= $hB= exists $h->{"logger"}
ABresult
0X0
100
111
420 0 ▶ return 0 if (!$lh);
Branch: 1 branch
BranchTrueFalseTotal
unless $lh 0 0 0
421  
422 0 ▶ if ($h && exists($h->{err_regexp})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h and exists $h->{"err_regexp"}) 0 0 0
Condition0%0/3
$h and exists $h->{"err_regexp"}
!ll&&!rl&&r
000
MC/DC0%0/2
$h and exists $h->{"err_regexp"}
$h exists $h->{"err_regexp"}
Truth table0%0/3
A and B
A= $hB= exists $h->{"err_regexp"}
ABresult
0X0
100
111
423 0 ▶ if ($dbh->err =~ $h->{err_regexp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err =~ /$h->{"err_regexp"}/) 0 0 0
424 0 goto FINISH;
425 }
426 }
427 # start with error message, state and err
428 0 $out .= ' ' . '=' x 60 . "\n $msg\n";
429 0 $out .= "err() = " . $handle->err . "\n";
430 0 $out .= "state() = " . $handle->state . "\n";
431  
432 0 ▶ if ($DBI::lasth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBI::lasth) 0 0 0
433 $out .= " lasth type: $DBI::lasth->{Type}\n"
434 0 ▶ if ($DBI::lasth->{Type});
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::lasth->{"Type"} 0 0 0
435 $out .= " lasth Statement ($DBI::lasth):\n " .
436 "$DBI::lasth->{Statement}\n"
437 0 ▶ if ($DBI::lasth->{Statement});
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::lasth->{"Statement"} 0 0 0
438 }
439 # get db handle if we have an st
440 0 my $type = $handle->{Type};
441 0 my $sql;
442 0 ▶ if ($type eq 'st') { # given statement handle
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'st') { } 0 0 0
443 0 $dbh = $handle->{Database};
444 0 $sql = $handle->{Statement};
445 } else {
446 # given db handle
447 # We've got other stmts under this db but we'll deal with those later
448 0 $sql = 'Possible SQL: ';
449 0 ▶ $sql .= "/$h->{Statement}/" if (exists($h->{Statement}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $h->{"Statement"} 0 0 0
450 $sql .= "/$dbh->{Statement}/"
451 if ($dbh->{Statement} &&
452 (exists($h->{Statement}) &&
453 0 ▶ ($dbh->{Statement} ne $h->{Statement})));
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->{"Statement"} and (exists $h->{"Statement"} and $dbh->{"Statement"} ne $h->{"Statement"}) 0 0 0
Condition0%0/6
$dbh->{"Statement"} and (exists $h->{"Statement"} and $dbh->{"Statement"} ne $h->{"Statement"})
!ll&&!rl&&r
000
exists $h->{"Statement"} and $dbh->{"Statement"} ne $h->{"Statement"}
!ll&&!rl&&r
000
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 table0%0/4
A and B and C
A= $dbh->{"Statement"}B= exists $h->{"Statement"}C= $dbh->{"Statement"} ne $h->{"Statement"}
ABCresult
0XX0
10X0
1100
1111
454 }
455  
456 0 ▶ my $dbname = exists($dbh->{Name}) ? $dbh->{Name} : "";
Branch: 1 branch
BranchTrueFalseTotal
exists $dbh->{'Name'} ? : 0 0 0
457 0 ▶ my $username = exists($dbh->{Username}) ? $dbh->{Username} : "";
Branch: 1 branch
BranchTrueFalseTotal
exists $dbh->{'Username'} ? : 0 0 0
458 0 $out .= " DB: $dbname, Username: $username\n";
459 0 $out .= " handle type: $type\n SQL: " . DBI::neat($sql) . "\n";
460 $out .= ' db Kids=' . $dbh->{Kids} .
461 0 ', ActiveKids=' . $dbh->{ActiveKids} . "\n";
462 0 ▶ $out .= " DB errstr: " . $handle->errstr . "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $handle->errstr and $handle->errstr ne $msg 0 0 0
Condition0%0/3
$handle->errstr and $handle->errstr ne $msg
!ll&&!rl&&r
000
MC/DC0%0/2
$handle->errstr and $handle->errstr ne $msg
$handle->errstr $handle->errstr ne $msg
Truth table0%0/3
A and B
A= $handle->errstrB= $handle->errstr ne $msg
ABresult
0X0
100
111
463 if ($handle->errstr && ($handle->errstr ne $msg));
464  
465 0 ▶ if (exists($h->{ParamValues}) && $h->{ParamValues}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h->{"ParamValues"} and $h->{"ParamValues"}) 0 0 0
Condition0%0/3
exists $h->{"ParamValues"} and $h->{"ParamValues"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $h->{"ParamValues"} and $h->{"ParamValues"}
exists $h->{"ParamValues"} $h->{"ParamValues"}
Truth table0%0/3
A and B
A= exists $h->{"ParamValues"}B= $h->{"ParamValues"}
ABresult
0X0
100
111
466 0 $out .= " ParamValues captured in HandleSetErr:\n ";
467 0 foreach (sort keys %{$h->{ParamValues}}) {
468 0 $out .= "$_=" . DBI::neat($h->{ParamValues}->{$_}) . ",";
469 }
470 0 $out .= "\n";
471 }
472 0 ▶ if ($type eq 'st') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "st") 0 0 0
473 0 my $str = "";
474 0 ▶ if ($handle->{ParamValues}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handle->{"ParamValues"}) 0 0 0
475 0 foreach (sort keys %{$handle->{ParamValues}}) {
476 0 $str .= "$_=" . DBI::neat($handle->{ParamValues}->{$_}) . ",";
477 }
478 }
479 0 $out .= " ParamValues: $str\n";
480 $out .= " " .
481 Data::Dumper->Dump([$handle->{ParamArrays}], ['ParamArrays'])
482 0 ▶ if ($handle->{ParamArrays});
Branch: 1 branch
BranchTrueFalseTotal
if $handle->{"ParamArrays"} 0 0 0
483 }
484 0 my @substmts;
485 # get list of statements under the db
486 0 push @substmts, $_ for (grep { defined } @{$dbh->{ChildHandles}});
487 0 $out .= " " . scalar(@substmts) . " sub statements:\n";
488 0 ▶ if (scalar(@substmts)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @substmts) 0 0 0
489 0 foreach my $stmt (@substmts) {
490 0 $out .= " stmt($stmt):\n";
491 $out .= ' SQL(' . $stmt->{Statement} . ")\n "
492 if ($stmt->{Statement} &&
493 (exists($h->{Statement}) &&
494 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
495 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
496 0 $out .= ' Params(';
497 0 foreach (sort keys %{$stmt->{ParamValues}}) {
498 0 $out .= "$_=" . DBI::neat($stmt->{ParamValues}->{$_}) . ",";
499 }
500 0 $out .= ")\n";
501 }
502 }
503 }
504  
505 0 ▶ if (exists($dbh->{Callbacks})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dbh->{"Callbacks"}) 0 0 0
506 $out .= " Callbacks exist for " .
507 0 join(",", keys(%{$dbh->{Callbacks}})) . "\n";
508 }
509 0 local $Carp::MaxArgLen = 256;
510 0 $out .= " " .Carp::longmess("DBI error trap");
511 0 $out .= " " . "=" x 60 . "\n";
512 0 $lh->fatal($out);
513  
514 FINISH:
515 0 ▶ if ($h && exists($h->{ErrorHandler})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h and exists $h->{'ErrorHandler'}) { } 0 0 0
Condition0%0/3
$h and exists $h->{"ErrorHandler"}
!ll&&!rl&&r
000
MC/DC0%0/2
$h and exists $h->{"ErrorHandler"}
$h exists $h->{"ErrorHandler"}
Truth table0%0/3
A and B
A= $hB= exists $h->{"ErrorHandler"}
ABresult
0X0
100
111
516 0 return $h->{ErrorHandler}($msg, $handle, $method_ret);
517 } else {
518 0 return 0; # pass error on
519 }
520 }
521  
522 #
523 # set_err handler so we can capture ParamValues before a statement
524 # is destroyed.
525 # If the use of DBIx::Log4perl passed in an error handler that is
526 # called before returning.
527 #
528 0 ▶sub _set_err_handler {
Subroutine _set_err_handler: not called CC=4 SCAR=30.0
529 0 my ($handle, $err, $errstr, $state, $method) = @_;
530  
531 # Capture ParamValues
532 0 ▶ if ($handle) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handle) 0 0 0
533 0 my $h = $handle->{private_DBIx_Log4perl};
534 $h->{ParamValues} = $handle->{ParamValues}
535 0 ▶ if (exists($handle->{ParamValues}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $handle->{"ParamValues"} 0 0 0
536 0 ▶ return $h->{HandleSetErr}(@_) if (exists($h->{HandleSetErr}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $h->{"HandleSetErr"} 0 0 0
537 }
538 0 return 0;
539 }
540  
541  
542 2 1;
↑ Summary Log4perl/st.pm »