LogAny.pm

filter: Statementstmt 31.0% 36 / 116 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 40.9% 9 / 22 Podpod 100% 4 / 4 totaltotal 23.0% 49 / 213 SCAR 62.6
CC
31
Cov
20%
connect
88.1
_dbix_la_debug
72.0
_dbix_la_error
30.0
CRAP 523.0
« LogAny/st.pm ↑ Summary LogAny/Constants.pm »
1 # $Id$
2 2 require 5.008;
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp qw(croak cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 package DBIx::LogAny;
11 2 ▶use DBIx::LogAny::Constants qw (:masks $LogMask);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use DBIx::LogAny::db;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use DBIx::LogAny::st;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 our $VERSION = '0.04';
16 2 require Exporter;
17 2 our @ISA = qw(Exporter DBI); # look in DBI for anything we don't do
18  
19 2 our @EXPORT = (); # export nothing by default
20 2 our @EXPORT_MASKS = qw(DBIX_LA_LOG_DEFAULT
21 DBIX_LA_LOG_ALL
22 DBIX_LA_LOG_INPUT
23 DBIX_LA_LOG_OUTPUT
24 DBIX_LA_LOG_CONNECT
25 DBIX_LA_LOG_TXN
26 DBIX_LA_LOG_ERRCAPTURE
27 DBIX_LA_LOG_WARNINGS
28 DBIX_LA_LOG_ERRORS
29 DBIX_LA_LOG_DBDSPECIFIC
30 DBIX_LA_LOG_DELAYBINDPARAM
31 DBIX_LA_LOG_SQL
32 DBIX_LA_LOG_STORE
33 );
34 2 our %EXPORT_TAGS= (masks => \@EXPORT_MASKS);
35 2 Exporter::export_ok_tags('masks'); # all tags must be in EXPORT_OK
36  
37 sub _dbix_la_debug {
38 0 ▶ my ($self, $h, $level, $thing, @args) = @_;
Subroutine _dbix_la_debug: not called CC=8 SCAR=42.8
39  
40 0 ▶ $h = $self->{private_DBIx_LogAny} if !defined($h);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h 0 0 0
41  
42 0 ▶ return unless $h->{logger}->is_debug();
Branch: 1 branch
BranchTrueFalseTotal
unless $h->{"logger"}->is_debug 0 0 0
43  
44 0 local $Data::Dumper::Indent = 0;
45 0 local $Data::Dumper::Quotekeys = 0;
46  
47 0 ▶ if (scalar(@args) > 1) {
Branch: 4 branches
BranchTrueFalseTotal
if (scalar @args > 1) { } 0 0 0
elsif (ref $thing eq 'CODE') { } 0 0 0
elsif (ref $args[0]) { } 0 0 0
elsif (scalar @args == 1) { } 0 0 0
48 $h->{logger}->debug(
49 0 Data::Dumper->Dump([\@args], [$thing]))
50 } elsif (ref($thing) eq 'CODE') {
51 0 $h->{logger}->debug($thing);
52 } elsif (ref($args[0])) {
53 $h->{logger}->debug(
54 0 Data::Dumper->Dump([$args[0]], [$thing]))
55 } elsif (scalar(@args) == 1) {
56 0 ▶ if (!defined($args[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args[0]) { } 0 0 0
57 0 $h->{logger}->debug("$thing:");
58 } else {
59 0 $h->{logger}->debug("$thing: " . DBI::neat($args[0]));
60 }
61 } else {
62 0 $h->{logger}->debug($thing);
63 }
64 0 return;
65 }
66  
67 sub _dbix_la_info {
68 0 ▶ my ($self, $level, $thing) = @_;
Subroutine _dbix_la_info: not called CC=2 SCAR=17.9
69  
70 0 my $h = $self->{private_DBIx_LogAny};
71  
72 0 ▶ return unless $h->{logger}->is_info();
Branch: 1 branch
BranchTrueFalseTotal
unless $h->{"logger"}->is_info 0 0 0
73  
74 0 $h->{logger}->info($thing);
75  
76 0 return;
77 }
78 sub _dbix_la_warning {
79 0 ▶ my ($self, $level, $thing, @args) = @_;
Subroutine _dbix_la_warning: not called CC=4 SCAR=30.0
80  
81 0 my $h = $self->{private_DBIx_LogAny};
82  
83 0 ▶ return unless $h->{logger}->is_warn();
Branch: 1 branch
BranchTrueFalseTotal
unless $h->{"logger"}->is_warn 0 0 0
84  
85 0 local $Data::Dumper::Indent = 0;
86 0 local $Data::Dumper::Quotekeys = 0;
87  
88 0 ▶ if (scalar(@args) > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @args > 1) { } 0 0 0
elsif (ref $args[0]) { } 0 0 0
89 $h->{logger}->warn(
90 0 ▶ sub {Data::Dumper->Dump([\@args], [$thing])})
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 0 } elsif (ref($args[0])) {
92 $h->{logger}->warn(
93 0 ▶ sub {Data::Dumper->Dump([$args[0]], [$thing])})
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 0 } else {
95 0 $h->{logger}->warn("$thing: " . DBI::neat($args[0]));
96 }
97 0 return;
98 }
99  
100 sub _dbix_la_error {
101 0 ▶ my ($self, $level, $thing, @args) = @_;
Subroutine _dbix_la_error: not called CC=5 SCAR=34.0
102  
103 0 my $h = $self->{private_DBIx_LogAny};
104  
105 0 ▶ return unless $h->{logger}->is_error();
Branch: 1 branch
BranchTrueFalseTotal
unless $h->{"logger"}->is_error 0 0 0
106  
107 0 local $Data::Dumper::Indent = 0;
108 0 local $Data::Dumper::Quotekeys = 0;
109  
110 0 ▶ if (scalar(@args) > 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (scalar @args > 1) { } 0 0 0
elsif (ref $thing eq 'CODE') { } 0 0 0
elsif (ref $args[0]) { } 0 0 0
111 $h->{logger}->error(
112 0 ▶ sub {Data::Dumper->Dump([\@args], [$thing])})
Subroutine __ANON__: not called CC=1 SCAR=6.9
113 0 } elsif (ref($thing) eq 'CODE') {
114 0 $h->{logger}->error($thing);
115 } elsif (ref($args[0])) {
116 $h->{logger}->error(
117 0 ▶ sub {Data::Dumper->Dump([$args[0]], [$thing])})
Subroutine __ANON__: not called CC=1 SCAR=6.9
118 0 } else {
119 0 $h->{logger}->error("$thing: " . DBI::neat($args[0]));
120 }
121 0 return;
122 }
123  
124 sub _dbix_la_attr_map {
125 return {
126 0 ▶ dbix_la_logmask => 'logmask',
Subroutine _dbix_la_attr_map: not called CC=1 SCAR=6.9
127 dbix_la_ignore_err_regexp => 'err_regexp',
128 dbix_la_category => 'category',
129 dbix_la_logger => 'logger'
130 };
131 }
132  
133 sub dbix_la_getattr {
134 0 ▶ my ($self, $item) = @_;
Subroutine dbix_la_getattr: not called CC=4 SCAR=30.0
Pod documented
135  
136 0 ▶ croak ('wrong arguments - dbix_la_getattr(attribute_name)')
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ != 2 or not defined $_[1] 0 0 0
Condition0%0/3
scalar @_ != 2 or not defined $_[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
scalar @_ != 2 or not defined $_[1]
scalar @_ != 2 not defined $_[1]
Truth table0%0/3
A or not(B)
A= scalar @_ != 2B= not defined $_[1]
ABresult
1X1
011
000
137 if (scalar(@_) != 2 || !defined($_[1]));
138  
139 0 my $m = _dbix_la_attr_map();
140  
141 0 my $h = $self->{private_DBIx_LogAny};
142  
143 0 ▶ if (!exists($m->{$item})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $m->{$item}) 0 0 0
144 0 warn "$item does not exist";
145 0 return;
146 }
147 0 return $h->{$m->{$item}};
148 }
149  
150 sub dbix_la_setattr {
151 0 ▶ my ($self, $item, $value) = @_;
Subroutine dbix_la_setattr: not called CC=4 SCAR=30.0
Pod documented
152  
153 0 ▶ croak ('wrong arguments - dbix_la_setattr(attribute_name, value)')
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ != 3 or not defined $_[1] 0 0 0
Condition0%0/3
scalar @_ != 3 or not defined $_[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
scalar @_ != 3 or not defined $_[1]
scalar @_ != 3 not defined $_[1]
Truth table0%0/3
A or not(B)
A= scalar @_ != 3B= not defined $_[1]
ABresult
1X1
011
000
154 if (scalar(@_) != 3 || !defined($_[1]));
155  
156 0 my $m = _dbix_la_attr_map();
157  
158 0 my $h = $self->{private_DBIx_LogAny};
159  
160 0 ▶ if (!exists($m->{$item})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $m->{$item}) 0 0 0
161 0 warn "$item does not exist";
162 0 return;
163 }
164 0 $h->{$m->{$item}} = $value;
165 0 1;
166 }
167  
168 sub connect {
169  
170 0 ▶ my ($drh, $dsn, $user, $pass, $attr) = @_;
Subroutine connect: not called CC=10 SCAR=44.8
Pod documented
171  
172 0 my $dbh = $drh->SUPER::connect($dsn, $user, $pass, $attr);
173 0 ▶ return $dbh if (!$dbh);
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh 0 0 0
174  
175 0 my $h = $dbh->{private_DBIx_LogAny};
176  
177 0 ▶ if ($h->{logmask} & DBIX_LA_LOG_CONNECT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"logmask"} & 4) 0 0 0
178 0 local $Data::Dumper::Indent = 0;
179 $h->{logger}->debug(
180 "connect($h->{dbh_no}): " .
181 (defined($dsn) ? $dsn : '') . ', ' .
182 (defined($user) ? $user : '') . ', ' .
183 Data::Dumper->Dump([$attr], [qw(attr)]))
184 0 ▶ if $h->{logger}->is_debug;
Branch: 3 branches
BranchTrueFalseTotal
if $h->{"logger"}->is_debug 0 0 0
defined $dsn ? : 0 0 0
defined $user ? : 0 0 0
185 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
186 0 my $v = "DBD::" . $dbh->{Driver}->{Name} . "::VERSION";
187 $h->{logger}->info("DBI: " . $DBI::VERSION,
188 ", DBIx::LogAny: " . $DBIx::LogAny::VERSION .
189 ", Driver: " . $h->{driver} . "(" .
190 $$v . ")")
191 0 ▶ if $h->{logger}->is_info;
Branch: 1 branch
BranchTrueFalseTotal
if $h->{"logger"}->is_info 0 0 0
192 }
193  
194 #
195 # Enable dbms_output for DBD::Oracle else turn off DBDSPECIFIC as we have
196 # no support for DBDSPECIFIC in any other drivers.
197 # BUT only enable it if the log handle is doing debug as we only call
198 # dbms_output_get in that case.
199 #
200 0 $h->{dbd_specific} = 1;
201 0 ▶ if (($h->{logger}->is_debug()) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{'logger'}->is_debug and $h->{'logmask'} & 128 and $h->{'driver'} eq 'Oracle') { } 0 0 0
Condition0%0/6
$h->{"logger"}->is_debug and $h->{"logmask"} & 128 and $h->{"driver"} eq "Oracle"
!ll&&!rl&&r
000
$h->{"logger"}->is_debug and $h->{"logmask"} & 128
!ll&&!rl&&r
000
MC/DC0%0/3
$h->{"logger"}->is_debug and $h->{"logmask"} & 128 and $h->{"driver"} eq "Oracle"
$h->{"logger"}->is_debug $h->{"logmask"} & 128 $h->{"driver"} eq "Oracle"
Truth table0%0/4
A and B and C
A= $h->{"logger"}->is_debugB= $h->{"logmask"} & 128C= $h->{"driver"} eq "Oracle"
ABCresult
0XX0
10X0
1100
1111
202 ($h->{logmask} & DBIX_LA_LOG_DBDSPECIFIC) &&
203 ($h->{driver} eq 'Oracle')) {
204 0 $dbh->func('dbms_output_enable');
205 } else {
206 0 $h->{logmask} &= ~DBIX_LA_LOG_DBDSPECIFIC;
207 }
208 0 $h->{dbd_specific} = 0;
209 0 return $dbh;
210 }
211  
212 sub dbix_la_logdie
213 {
214 0 ▶ my ($drh, $msg) = @_;
Subroutine dbix_la_logdie: not called CC=1 SCAR=6.9
Pod documented
215 0 _error_handler($msg, $drh);
216 0 die "$msg";
217 }
218  
219 2 1;
220  
221 __END__
« LogAny/st.pm ↑ Summary LogAny/Constants.pm »