Wrapper/DBIDelegator.pm

filter: Statementstmt 22.0% 17 / 77 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 22.2% 4 / 18 Podpod 0.0% 0 / 1 totaltotal 18.4% 21 / 114 CC 7 SCAR 21.2
CC
7
Cov
19%
FETCH
30.0
refaddr
6.0
_new
6.0
CRAP 8.3
« Wrapper/StatementLoop.pm ↑ Summary Wrapper/SelectLoop.pm »
1 # Creation date: 2005-10-16 20:42:19
2 # Authors: don
3  
4 # Copyright (c) 2005-2012 Don Owens <don@owensnet.com>. All rights reserved.
5  
6 # This is free software; you can redistribute it and/or modify it
7 # under the same terms as Perl itself. See perlartistic.
8  
9 # This program is distributed in the hope that it will be
10 # useful, but WITHOUT ANY WARRANTY; without even the implied
11 # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 # PURPOSE.
13  
14 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 package DBIx::Wrapper::DBIDelegator;
18  
19 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 $VERSION = do { my @r=(q$Revision: 1963 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r };
21  
22 # use Scalar::Util qw(refaddr);
23 2 ▶use Carp qw(cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 my %i_data;
26  
27 0 ▶sub refaddr($) {
Subroutine refaddr: not called CC=2 SCAR=17.9
Pod undocumented
28 0 my $obj = shift;
29 0 ▶ my $pkg = ref($obj) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $pkg = ref $obj or return undef 0 0 0
30 0 bless $obj, 'DBIx::Wrapper::Fake';
31 0 my $i = int($obj);
32 0 bless $obj, $pkg;
33 0 return $i;
34 }
35  
36  
37 0 ▶sub _new {
Subroutine _new: not called CC=2 SCAR=17.9
38 0 my $proto = shift;
39 0 ▶ my $self = bless {}, ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
40 0 $i_data{ refaddr($self) } = {};
41 0 return $self;
42 }
43  
44 0 ▶sub TIEHASH {
Subroutine TIEHASH: not called CC=1 SCAR=6.9
45 0 my $proto = shift;
46 0 my $dbix_dbh = shift;
47  
48 0 my $self = $proto->_new;
49 0 $i_data{ refaddr($self) }{_dbix_dbh} = $dbix_dbh;
50  
51 0 return $self;
52 }
53  
54 0 ▶sub _get_dbi {
Subroutine _get_dbi: not called CC=1 SCAR=6.9
55 0 my $self = shift;
56 0 return $i_data{ refaddr($self) }{_dbix_dbh}->get_dbi;
57 }
58  
59 0 ▶sub FETCH {
Subroutine FETCH: not called CC=5 SCAR=34.0
60 0 my $self = shift;
61 0 my $key = shift;
62  
63 0 ▶ if ($key =~ /\A_(?:dbh|username|auth|attr|data_source_str|dbd_driver|db_style|debug)\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /\A_(?:dbh|username|auth|attr|data_source_str|dbd_driver|db_style|debug)\Z/) 0 0 0
64 0 my ($package, $filename, $line, $subroutine, $hasargs,
65 $wantarray, $evaltext, $is_require, $hints, $bitmask);
66
67 0 my $frame = 1;
68 0 my $this_pkg = __PACKAGE__;
69
70 0 ($package, $filename, $line, $subroutine, $hasargs,
71 $wantarray, $evaltext, $is_require, $hints, $bitmask) = caller($frame);
72 0 ▶ while (defined($package) and $package eq $this_pkg) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $package and $package eq $this_pkg) 0 0 0
Condition0%0/3
defined $package and $package eq $this_pkg
!ll&&!rl&&r
000
MC/DC0%0/2
defined $package and $package eq $this_pkg
defined $package $package eq $this_pkg
Truth table0%0/3
A and B
A= defined $packageB= $package eq $this_pkg
ABresult
0X0
100
111
73 0 $frame++;
74 0 ($package, $filename, $line, $subroutine, $hasargs,
75 $wantarray, $evaltext, $is_require, $hints, $bitmask) = caller($frame);
76
77 # if we get more than 10 something must be wrong
78 0 ▶ last if $frame >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if $frame >= 10 0 0 0
79 }
80
81 0 local($Carp::CarpLevel) = $frame;
82  
83 0 cluck "Accessing DBIx::Wrapper's internal data directly. Don't do that.";
84 }
85
86 0 return $self->_get_dbi()->{$key};
87 }
88  
89 0 ▶sub STORE {
Subroutine STORE: not called CC=1 SCAR=6.9
90 0 my $self = shift;
91 0 my $key = shift;
92 0 my $value = shift;
93 0 my $dbi = $self->_get_dbi;
94  
95 0 $self->_get_dbi()->{$key} = $value;
96 0 return $value;
97 }
98  
99 0 ▶sub DELETE {
Subroutine DELETE: not called CC=1 SCAR=6.9
100 0 my $self = shift;
101 0 my $key = shift;
102  
103 0 return delete $self->_get_dbi()->{$key};
104 }
105  
106 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=1 SCAR=6.9
107 0 my $self = shift;
108  
109 0 %{ $self->_get_dbi() } = ();
110 }
111  
112 0 ▶sub EXISTS {
Subroutine EXISTS: not called CC=1 SCAR=6.9
113 0 my $self = shift;
114 0 my $key = shift;
115  
116 0 return exists $self->_get_dbi()->{$key};
117 }
118  
119 0 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: not called CC=1 SCAR=6.9
120 0 my $self = shift;
121 0 my $dbi = $self->_get_dbi;
122 0 my $cnt = keys %$dbi; # reset each() iterator
123 0 return each %$dbi;
124 }
125  
126 0 ▶sub NEXTKEY {
Subroutine NEXTKEY: not called CC=1 SCAR=6.9
127 0 my $self = shift;
128 0 my $last_key = shift;
129
130 0 return each %{ $self->_get_dbi };
131 }
132  
133 0 ▶sub SCALAR {
Subroutine SCALAR: not called CC=1 SCAR=6.9
134 0 my $self = shift;
135  
136 0 return scalar(%{ $self->_get_dbi });
137 }
138  
139 0 ▶sub UNTIE {
Subroutine UNTIE: not called CC=1 SCAR=0.0
140 # noop
141 }
142  
143 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
144 0 my $self = shift;
145
146 0 delete $i_data{ refaddr($self) };
147 0 return;
148 }
149  
150 2 1;
151  
152 # Local Variables: #
153 # mode: perl #
154 # tab-width: 4 #
155 # indent-tabs-mode: nil #
156 # cperl-indent-level: 4 #
157 # perl-indent-level: 4 #
158 # End: #
159 # vim:set ai si et sta ts=4 sw=4 sts=4:
« Wrapper/StatementLoop.pm ↑ Summary Wrapper/SelectLoop.pm »