blib/lib/DBD/PassThrough.pm

filter: Statementstmt 41.7% 28 / 67 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 45.4% 5 / 11 Podpod 0.0% 0 / 1 totaltotal 30.8% 33 / 107 CC 14 SCAR 34.6
CC
14
Cov
31%
driver
70.9
FETCH
20.0
STORE
12.0
CRAP 31.9
↑ Summary
1 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package DBD::PassThrough;
5 1 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 our $VERSION = '0.02';
7  
8 {
9 package DBD::PassThrough;
10 1 require DBI;
11 1 DBI->require_version(1.0201);
12  
13 1 our $drh = undef; # holds driver handle(s) once initialized
14 1 our $imp_data_size = 0;
15  
16 0 ▶ sub driver($;$) {
Subroutine driver: not called CC=9 SCAR=42.6
Pod undocumented
17 0 my ($class, $attr) = @_;
18 0 ▶ $drh->{$class} and return $drh->{$class}; # Is this line needed?
Branch: 1 branch
BranchTrueFalseTotal
$DBD::PassThrough::drh->{$class} and return $DBD::PassThrough::drh->{$class} 0 0 0
19  
20 0 ▶ $attr ||= +{};
Condition0%0/2
$attr ||= {}
l!l
00
MC/DC0%0/1
$attr ||= {}
$attr
Truth table0%0/2
A
A= $attr
Aresult
11
00
21 0 ▶ $attr->{Attribution} ||= __PACKAGE__ . ' by tokuhirom';
Condition0%0/2
$attr->{"Attribution"} ||= "DBD::PassThrough by tokuhirom"
l!l
00
MC/DC0%0/1
$attr->{"Attribution"} ||= "DBD::PassThrough by tokuhirom"
$attr->{"Attribution"}
Truth table0%0/2
A
A= $attr->{"Attribution"}
Aresult
11
00
22 0 ▶ $attr->{Version} ||= $VERSION;
Condition0%0/3
$attr->{"Version"} ||= $DBD::PassThrough::VERSION
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr->{"Version"} ||= $DBD::PassThrough::VERSION
$attr->{"Version"} $DBD::PassThrough::VERSION
Truth table0%0/3
A ||= B
A= $attr->{"Version"}B= $DBD::PassThrough::VERSION
ABresult
1X1
011
000
23 0 ▶ $attr->{Name} ||= 'PassThrough';
Condition0%0/2
$attr->{"Name"} ||= "PassThrough"
l!l
00
MC/DC0%0/1
$attr->{"Name"} ||= "PassThrough"
$attr->{"Name"}
Truth table0%0/2
A
A= $attr->{"Name"}
Aresult
11
00
24  
25 # Make delegater methods
26 # This is needed like '$dbh->func("last_insert_rowid")'
27 {
28 0 my %drivers = DBI->installed_drivers;
29 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 0 for my $db_class (keys %drivers) {
31 0 my @meth = grep !/^[_A-Z]/, keys %{"DBD::${db_class}::db::"};
32 0 for my $meth (sort @meth) {
33 0 ▶ next if DBD::PassThrough::db->can($meth);
Branch: 1 branch
BranchTrueFalseTotal
if "DBD::PassThrough::db"->can($meth) 0 0 0
34 0 ▶ *{"DBD::PassThrough::db::${meth}"} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 0 my $dbh = shift;
36 0 return $dbh->{pass_through_source}->func($meth => @_);
37 0 };
38 }
39 }
40 }
41  
42 0 $drh->{$class} = DBI::_new_drh( $class . "::dr", $attr );
43 0 return $drh->{$class};
44 }
45 }
46  
47 {
48 1 package DBD::PassThrough::dr;
49 1 our $imp_data_size = 0;
50 }
51  
52 {
53 1 package DBD::PassThrough::db;
54 1 our $imp_data_size = 0;
55 0 ▶ sub STORE {
Subroutine STORE: not called CC=3 SCAR=24.8
56 0 my ($dbh, $attrib, $value) = @_;
57 0 ▶ if ($dbh->{pass_through_source}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{"pass_through_source"}) 0 0 0
58 0 return $dbh->{pass_through_source}->STORE($attrib, $value);
59 }
60 0 ▶ if ($attrib eq 'pass_through_source') {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib eq "pass_through_source") 0 0 0
61 0 $dbh->{pass_through_source} = $value;
62 0 return;
63 }
64 0 return $dbh->set_err($DBI::stderr, "Can't alter \$dbh->{$attrib} after handle created with DBD::PassThrough");
65 }
66 0 ▶ sub FETCH {
Subroutine FETCH: not called CC=4 SCAR=30.0
67 0 my ($dbh, $attrib) = @_;
68 0 ▶ if ($attrib eq 'pass_through_source') {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib eq "pass_through_source") 0 0 0
69 0 return $dbh->{pass_through_source};
70 }
71 0 ▶ if ($dbh->{pass_through_source}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{"pass_through_source"}) 0 0 0
72 0 return $dbh->{pass_through_source}->FETCH($attrib);
73 }
74 0 ▶ if ($attrib eq 'Active') {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib eq "Active") 0 0 0
75 0 return 0; # pass_through_source is not set yet.
76 }
77 0 return $dbh->set_err($DBI::stderr, "Can't fetch \$dbh->{$attrib} before connect with DBD::PassThrough");
78 }
79
80 # do not disconnect parent handle.
81 0 ▶ sub disconnect {
Subroutine disconnect: not called CC=1 SCAR=6.9
82 0 my $dbh = shift;
83 0 delete $dbh->{pass_through_source};
84 0 return 1;
85 }
86  
87 # Generate methods
88 1 for my $meth (qw(prepare table_info get_info type_info_all type_info column_info primary_key_info primary_key foreign_key_info tables quote quote_identifier)) {
89 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
90 12 ▶ *{"DBD::PassThrough::db::${meth}"} = sub {
Subroutine __ANON__: not called CC=1 SCAR=2.6
91 0 my $dbh = shift;
92 0 return $dbh->{pass_through_source}->$meth(@_);
93 12 };
94 }
95 }
96  
97 1 1;
98 __END__
↑ Summary