blib/lib/DBD/NullP.pm

filter: Statementstmt 87.5% 91 / 104 Branchbran 53.3% 16 / 30 Conditioncond 52.1% 12 / 23 MC/DCmcdc 15.3% 2 / 13 Subroutinesub 90.9% 20 / 22 Podpod 0.0% 0 / 1 totaltotal 73.0% 141 / 193 CC 25 SCAR 18.9
CC
25
Cov
76%
execute
15.4
table_info
14.2
STORE
5.6
CRAP 6.6
« blib/lib/DBD/ExampleP.pm ↑ Summary blib/lib/DBI/Gofer/Transport/stream.pm »
1 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 {
4 package DBD::NullP;
5  
6 14 require DBI;
7 14 require Carp;
8  
9 14 our @EXPORT = qw(); # Do NOT @EXPORT anything.
10 14 our $VERSION = "12.014715";
11  
12 # $Id: NullP.pm 14714 2011-02-22 17:27:07Z Tim $
13 #
14 # Copyright (c) 1994-2007 Tim Bunce
15 #
16 # You may distribute under the terms of either the GNU General Public
17 # License or the Artistic License, as specified in the Perl README file.
18  
19 14 our $drh = undef; # holds driver handle once initialised
20  
21 14 ▶ sub driver{
Subroutine driver: called CC=2 SCAR=7.0
Pod undocumented
22 14 ▶ return $drh if $drh;
Branch: 1 branch
BranchTrueFalseTotal
if $DBD::NullP::drh 0 14 14
23 14 my($class, $attr) = @_;
24 14 $class .= "::dr";
25 14 ($drh) = DBI::_new_drh($class, {
26 'Name' => 'NullP',
27 'Version' => $VERSION,
28 'Attribution' => 'DBD Example Null Perl stub by Tim Bunce',
29 }, [ qw'example implementors private data']);
30 14 $drh;
31 }
32  
33 0 ▶ sub CLONE {
Subroutine CLONE: not called CC=1 SCAR=6.9
34 0 undef $drh;
35 }
36 }
37  
38  
39 14 { package DBD::NullP::dr; # ====== DRIVER ======
40 14 our $imp_data_size = 0;
41 14 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 29 ▶ sub connect { # normally overridden, but a handy default
Subroutine connect: called CC=2 SCAR=7.1
44 29 ▶ my $dbh = shift->SUPER::connect(@_)
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = (shift())->SUPER::connect(@_) or return 29 0 29
45 or return;
46 29 $dbh->STORE(Active => 1);
47 29 $dbh;
48 }
49  
50  
51 0 ▶ sub DESTROY { undef }
Subroutine DESTROY: not called CC=1 SCAR=6.9
52 }
53  
54  
55 14 { package DBD::NullP::db; # ====== DATABASE ======
56 14 our $imp_data_size = 0;
57 14 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 14 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 # Added get_info to support tests in 10examp.t
61 16 ▶ sub get_info {
Subroutine get_info: called CC=2 SCAR=6.9
62 16 my ($dbh, $type) = @_;
63  
64 16 ▶ if ($type == 29) { # identifier quote
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 29) 8 8 16
65 8 return '"';
66 }
67 8 return;
68 }
69  
70 # Added table_info to support tests in 10examp.t
71 8 ▶ sub table_info {
Subroutine table_info: called CC=9 SCAR=26.5
72 8 my ($dbh, $catalog, $schema, $table, $type) = @_;
73  
74 8 my ($outer, $sth) = DBI::_new_sth($dbh, {
75 'Statement' => 'tables',
76 });
77 8 ▶ if (defined($type) && $type eq '%' && # special case for tables('','','','%')
Branch: 2 branches
BranchTrueFalseTotal
if (defined $type and $type eq '%' and grep {defined $_ and $_ eq '';} $catalog, $schema, $table) { } 4 4 8
elsif (defined $catalog and $catalog eq '%' and grep {defined $_ and $_ eq '';} $schema, $table) { } 4 0 4
Condition66%4/6
defined $type and $type eq "%" and grep {defined $_ and $_ eq "";} $catalog, $schema, $table
!ll&&!rl&&r
404
defined $type and $type eq "%"
!ll&&!rl&&r
404
MC/DC33%1/3
defined $type and $type eq "%" and grep {defined $_ and $_ eq "";} $catalog, $schema, $table
defined $type $type eq "%" grep {defined $_ and $_ eq "";} $catalog, $schema, $table
Truth table50%2/4
A and B and C
A= defined $typeB= $type eq "%"C= grep {defined $_ and $_ eq "";} $catalog, $schema, $table
ABCresult
0XX0
10X0
1100
1111
78 12 ▶ grep {defined($_) && $_ eq ''} ($catalog, $schema, $table)) {
Condition33%1/3
defined $_ && $_ eq ''
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $_ && $_ eq ''
defined $_ $_ eq ''
Truth table33%1/3
A && B
A= defined $_B= $_ eq ''
ABresult
0X0
100
111
79 4 $outer->{dbd_nullp_data} = [[undef, undef, undef, 'TABLE', undef],
80 [undef, undef, undef, 'VIEW', undef],
81 [undef, undef, undef, 'ALIAS', undef]];
82 ▶ } elsif (defined($catalog) && $catalog eq '%' && # special case for tables('%','','')
Condition33%2/6
defined $catalog and $catalog eq "%" and grep {defined $_ and $_ eq "";} $schema, $table
!ll&&!rl&&r
004
defined $catalog and $catalog eq "%"
!ll&&!rl&&r
004
MC/DC0%0/3
defined $catalog and $catalog eq "%" and grep {defined $_ and $_ eq "";} $schema, $table
defined $catalog $catalog eq "%" grep {defined $_ and $_ eq "";} $schema, $table
Truth table25%1/4
A and B and C
A= defined $catalogB= $catalog eq "%"C= grep {defined $_ and $_ eq "";} $schema, $table
ABCresult
0XX0
10X0
1100
1111
83 8 ▶ grep {defined($_) && $_ eq ''} ($schema, $table)) {
Condition33%1/3
defined $_ && $_ eq ''
!ll&&!rl&&r
008
MC/DC0%0/2
defined $_ && $_ eq ''
defined $_ $_ eq ''
Truth table33%1/3
A && B
A= defined $_B= $_ eq ''
ABresult
0X0
100
111
84 4 $outer->{dbd_nullp_data} = [['catalog1', undef, undef, undef, undef],
85 ['catalog2', undef, undef, undef, undef]];
86 } else {
87 0 $outer->{dbd_nullp_data} = [['catalog', 'schema', 'table1', 'TABLE']];
88 0 $outer->{dbd_nullp_data} = [['catalog', 'schema', 'table2', 'TABLE']];
89 0 $outer->{dbd_nullp_data} = [['catalog', 'schema', 'table3', 'TABLE']];
90 }
91 8 $outer->STORE(NUM_OF_FIELDS => 5);
92 8 $sth->STORE(Active => 1);
93 8 return $outer;
94 }
95  
96 9 ▶ sub prepare {
Subroutine prepare: called CC=1 SCAR=0.0
97 9 my ($dbh, $statement)= @_;
98  
99 9 my ($outer, $sth) = DBI::_new_sth($dbh, {
100 'Statement' => $statement,
101 });
102  
103 9 return $outer;
104 }
105  
106 108 ▶ sub FETCH {
Subroutine FETCH: called CC=1 SCAR=0.0
107 108 my ($dbh, $attrib) = @_;
108 # In reality this would interrogate the database engine to
109 # either return dynamic values that cannot be precomputed
110 # or fetch and cache attribute values too expensive to prefetch.
111 108 return $dbh->SUPER::FETCH($attrib);
112 }
113  
114 237 ▶ sub STORE {
Subroutine STORE: called CC=5 SCAR=17.2
115 237 my ($dbh, $attrib, $value) = @_;
116 # would normally validate and only store known attributes
117 # else pass up to DBI to handle
118 237 ▶ if ($attrib eq 'AutoCommit') {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrib eq 'AutoCommit') { } 30 207 237
elsif ($attrib eq 'nullp_set_err') { } 0 207 207
119 30 ▶ Carp::croak("Can't disable AutoCommit") unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 30 30
120 # convert AutoCommit values to magic ones to let DBI
121 # know that the driver has 'handled' the AutoCommit attribute
122 30 ▶ $value = ($value) ? -901 : -900;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 30 0 30
123 } elsif ($attrib eq 'nullp_set_err') {
124 # a fake attribute to produce a test case where STORE issues a warning
125 0 $dbh->set_err($value, $value);
126 }
127 237 return $dbh->SUPER::STORE($attrib, $value);
128 }
129  
130 14 ▶ sub ping { 1 }
Subroutine ping: called CC=1 SCAR=0.0
131  
132 6 ▶ sub disconnect {
Subroutine disconnect: called CC=1 SCAR=0.0
133 6 shift->STORE(Active => 0);
134 }
135  
136 }
137  
138  
139 14 { package DBD::NullP::st; # ====== STATEMENT ======
140 14 our $imp_data_size = 0;
141 14 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
142  
143 6000 ▶ sub bind_param {
Subroutine bind_param: called CC=2 SCAR=7.0
144 6000 my ($sth, $param, $value, $attr) = @_;
145 6000 $sth->{ParamValues}{$param} = $value;
146 6000 ▶ $sth->{ParamAttr}{$param} = $attr
Branch: 1 branch
BranchTrueFalseTotal
if defined $attr 0 6000 6000
147 if defined $attr; # attr is sticky if not explicitly set
148 6000 return 1;
149 }
150  
151 2 ▶ sub execute {
Subroutine execute: called CC=7 SCAR=27.3
152 2 my $sth = shift;
153 2 $sth->bind_param($_, $_[$_-1]) for (1..@_);
154 2 ▶ if ($sth->{Statement} =~ m/^ \s* SELECT \s+/xmsi) {
Branch: 3 branches
BranchTrueFalseTotal
if ($sth->{'Statement'} =~ /^ \s* SELECT \s+/imsx) { } 2 0 2
elsif ($sth->{'Statement'} =~ /^ \s* SLEEP \s+ (\S+) /imsx) { } 0 0 0
elsif ($sth->{'Statement'} =~ /^ \s* ERROR \s+ (\d+) \s* (.*) /imsx) { } 0 0 0
155 2 $sth->STORE(NUM_OF_FIELDS => 1);
156 2 $sth->{NAME} = [ "fieldname" ];
157 # just for the sake of returning something, we return the params
158 2 ▶ my $params = $sth->{ParamValues} || {};
Condition50%1/2
$sth->{'ParamValues'} || {}
l!l
20
MC/DC0%0/1
$sth->{'ParamValues'} || {}
$sth->{'ParamValues'}
Truth table50%1/2
A
A= $sth->{'ParamValues'}
Aresult
11
00
159 2 $sth->{dbd_nullp_data} = [ @{$params}{ sort keys %$params } ];
160 2 $sth->STORE(Active => 1);
161 }
162 # force a sleep - handy for testing
163 elsif ($sth->{Statement} =~ m/^ \s* SLEEP \s+ (\S+) /xmsi) {
164 0 my $secs = $1;
165 0 ▶ if (eval { require Time::HiRes; defined &Time::HiRes::sleep }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Time::HiRes; defined &Time::HiRes::sleep } }) { } 0 0 0
166 0 Time::HiRes::sleep($secs);
167 }
168 else {
169 0 sleep $secs;
170 }
171 }
172 # force an error - handy for testing
173 elsif ($sth->{Statement} =~ m/^ \s* ERROR \s+ (\d+) \s* (.*) /xmsi) {
174 0 return $sth->set_err($1, $2);
175 }
176 # anything else is silently ignored, successfully
177 2 1;
178 }
179  
180 29 ▶ sub fetchrow_arrayref {
Subroutine fetchrow_arrayref: called CC=3 SCAR=11.0
181 29 my $sth = shift;
182 29 my $data = shift @{$sth->{dbd_nullp_data}};
183 29 ▶ if (!$data || !@$data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data and @$data) 8 20 28
Condition100%3/3
$data and @$data
!ll&&!rl&&r
8120
MC/DC50%1/2
$data and @$data
$data @$data
Truth table66%2/3
A and B
A= $dataB= @$data
ABresult
0X0
100
111
184 8 $sth->finish; # no more data so finish
185 8 return undef;
186 }
187 20 return $sth->_set_fbav($data);
188 }
189 14 *fetch = \&fetchrow_arrayref; # alias
190  
191 69 ▶ sub FETCH {
Subroutine FETCH: called CC=1 SCAR=0.0
192 69 my ($sth, $attrib) = @_;
193 # would normally validate and only fetch known attributes
194 # else pass up to DBI to handle
195 69 return $sth->SUPER::FETCH($attrib);
196 }
197  
198 29 ▶ sub STORE {
Subroutine STORE: called CC=1 SCAR=0.0
199 29 my ($sth, $attrib, $value) = @_;
200 # would normally validate and only store known attributes
201 # else pass up to DBI to handle
202 29 return $sth->SUPER::STORE($attrib, $value);
203 }
204  
205 }
206  
207 14 1;
« blib/lib/DBD/ExampleP.pm ↑ Summary blib/lib/DBI/Gofer/Transport/stream.pm »