blib/lib/DBIx/Objects.pm

filter: Statementstmt 10.6% 24 / 225 Branchbran 0.0% 0 / 82 Conditioncond 0.0% 0 / 114 MC/DCmcdc 0.0% 0 / 64 Subroutinesub 22.2% 8 / 36 Podpod n/a totaltotal 6.1% 32 / 521 CC 86 SCAR 39.2
CC
86
Cov
6%
AUTOLOAD
207.9
_readonly
56.0
_validate
56.0
CRAP 50.5
↑ Summary
1 package DBIx::Objects;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings qw(all);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $VERSION=0.04;
9 }
10  
11 ###
12  
13 package DBIx::Object;
14  
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use warnings qw(all);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # Back-end methods
19 0 ▶sub _blank { # Default back-end for constructor
Subroutine _blank: not called CC=5 SCAR=34.0
20 # ARGS: $self, [$namespace,] @arglist
21 # $namespace - Scalar (string) - Namespace of managing package for variables
22 # @arglist - Array (string) - List of variables to be registered as methods
23 0 my $self=shift;
24 0 ▶ my $package=
Condition0%0/6
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || caller
l!l&&r!l&&!r
000
UNIVERSAL::isa($_[0], __PACKAGE__) and shift()
!ll&&!rl&&r
000
MC/DC0%0/3
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || caller
UNIVERSAL::isa($_[0], __PACKAGE__) shift() caller
Truth table0%0/5
A and B || C
A= UNIVERSAL::isa($_[0], __PACKAGE__)B= shift()C= caller
ABCresult
11X1
0X11
1011
0X00
1000
25 (UNIVERSAL::isa($_[0],__PACKAGE__) && # Looks like a descendant
26 shift) || caller; # Shift or autodetect namespace to register
27 warn "Package $package not listed in registry"
28 0 ▶ unless defined($self->{_REGISTRY}{$package});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_REGISTRY"}{$package} 0 0 0
29 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
30 0 local $_=uc(shift);
31 0 $self->{$_}=undef;
32 0 $self->{_REGISTRY}{_DATA}{$_}{source}=$package;
33 0 $self->{_REGISTRY}{_DATA}{$_}{access}=1; # default to rw
34 0 $self->{_REGISTRY}{_DATA}{$_}{type}="basic";
35 }
36 }
37  
38 0 ▶sub _register { # Default back-end for package registration
Subroutine _register: not called CC=2 SCAR=17.9
39 # Call immediately after being bless()ed
40 0 my $self=shift;
41 0 my $package=caller;
42 0 ▶ $self->{_REGISTRY}{$package}{prep}=0 unless (defined($self->{_REGISTRY}{$package}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_REGISTRY"}{$package} 0 0 0
43 0 return defined($self->{_REGISTRY}{$package});
44 }
45  
46 0 ▶sub _unregister{# Default back-end for package de-registration
Subroutine _unregister: not called CC=1 SCAR=6.9
47 # If you wish to partially destruct an object, make sure to call this
48 # from each namespace being removed from the object
49 0 my $self=shift;
50 0 my $package=caller;
51 0 $self->_taint($package);
52 0 undef $self->{_REGISTRY}{$package};
53 0 return (!(defined($self->{_REGISTRY}{$package})));
54 }
55  
56 0 ▶sub _primary { # Sets/detects whether a namespace contains the primary key
Subroutine _primary: not called CC=5 SCAR=34.0
57 # Used internally to assure that the primary key's namespace is always
58 # in sync with the rest of the object
59 0 my $self=shift;
60 0 ▶ my $package=(UNIVERSAL::isa($_[0],__PACKAGE__) && shift) || caller;
Condition0%0/6
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || caller
l!l&&r!l&&!r
000
UNIVERSAL::isa($_[0], __PACKAGE__) and shift()
!ll&&!rl&&r
000
MC/DC0%0/3
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || caller
UNIVERSAL::isa($_[0], __PACKAGE__) shift() caller
Truth table0%0/5
A and B || C
A= UNIVERSAL::isa($_[0], __PACKAGE__)B= shift()C= caller
ABCresult
11X1
0X11
1011
0X00
1000
61 0 ▶ if ($_[0]) {$self->{_REGISTRY}{_PRIMARY}=$package;$self->_taint;}
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) 0 0 0
62 0 ▶ return ($self->{_REGISTRY}{_PRIMARY} || 0);
Condition0%0/2
$self->{'_REGISTRY'}{'_PRIMARY'} || 0
l!l
00
MC/DC0%0/1
$self->{'_REGISTRY'}{'_PRIMARY'} || 0
$self->{'_REGISTRY'}{'_PRIMARY'}
Truth table0%0/2
A
A= $self->{'_REGISTRY'}{'_PRIMARY'}
Aresult
11
00
63 }
64  
65 0 ▶sub _readonly { # Sets/detects whether a data mehod is tagged read-only
Subroutine _readonly: not called CC=7 SCAR=40.3
66 # Used by AUTOLOAD to detect read-only method calls
67 0 my $self=shift;
68 0 ▶ my $package=(UNIVERSAL::isa($_[0],__PACKAGE__) && shift) || caller;
Condition0%0/6
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || caller
l!l&&r!l&&!r
000
UNIVERSAL::isa($_[0], __PACKAGE__) and shift()
!ll&&!rl&&r
000
MC/DC0%0/3
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || caller
UNIVERSAL::isa($_[0], __PACKAGE__) shift() caller
Truth table0%0/5
A and B || C
A= UNIVERSAL::isa($_[0], __PACKAGE__)B= shift()C= caller
ABCresult
11X1
0X11
1011
0X00
1000
69 0 my $var=uc(shift);
70 0 ▶ if (@_) {local $_=shift;$self->{_REGISTRY}{_DATA}{$var}{access}=(!($_)?1:0) if (/[01]/);} #Set to "0" to catch in this check next time
Branch: 3 branches
BranchTrueFalseTotal
if (@_) 0 0 0
if /[01]/ 0 0 0
!$_ ? : 0 0 0
71 return (!($self->{_REGISTRY}{_DATA}{$var}{access}) ||
72 0 ▶ $self->{_REGISTRY}{_DATA}{$var}{source} eq $self->_primary);
Condition0%0/3
!$self->{'_REGISTRY'}{'_DATA'}{$var}{'access'} || $self->{'_REGISTRY'}{'_DATA'}{$var}{'source'} eq $self->_primary
l!l&&r!l&&!r
000
MC/DC0%0/2
!$self->{'_REGISTRY'}{'_DATA'}{$var}{'access'} || $self->{'_REGISTRY'}{'_DATA'}{$var}{'source'} eq $self->_primary
!$self->{'_REGISTRY'}{'_DATA'}{$var}{'access'} $self->{'_REGISTRY'}{'_DATA'}{$var}{'source'} eq $self->_primary
Truth table0%0/3
not(A) || B
A= !$self->{'_REGISTRY'}{'_DATA'}{$var}{'access'}B= $self->{'_REGISTRY'}{'_DATA'}{$var}{'source'} eq $self->_primary
ABresult
1X1
011
000
73 }
74  
75 0 ▶sub _validate { # Marks a namespace as tied to the back-end database
Subroutine _validate: not called CC=7 SCAR=40.3
76 # Intended to be called on first refresh - Paired with _taint
77 0 my $self=shift;
78 0 ▶ my $package=shift || caller;
Condition0%0/3
shift() || caller
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || caller
shift() caller
Truth table0%0/3
A || B
A= shift()B= caller
ABresult
1X1
011
000
79 0 ▶ (my @vars=$self->_vars($package)) || return $self;
Branch: 1 branch
BranchTrueFalseTotal
my(@vars) = $self->_vars($package) or return $self 0 0 0
80 0 foreach my $var (@vars) {
81 0 ▶ if ($self->_isobject($var)) { # Reset embedded object information (only if needed)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_isobject($var)) 0 0 0
82 0 ▶ unless ($self->{var} && ($self->{_REGISTRY}{_DATA}{$var}{data} eq $self->{$var})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"var"} and $self->{"_REGISTRY"}{"_DATA"}{$var}{"data"} eq $self->{$var}) 0 0 0
Condition0%0/3
$self->{"var"} and $self->{"_REGISTRY"}{"_DATA"}{$var}{"data"} eq $self->{$var}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"var"} and $self->{"_REGISTRY"}{"_DATA"}{$var}{"data"} eq $self->{$var}
$self->{"var"} $self->{"_REGISTRY"}{"_DATA"}{$var}{"data"} eq $self->{$var}
Truth table0%0/3
A and B
A= $self->{"var"}B= $self->{"_REGISTRY"}{"_DATA"}{$var}{"data"} eq $self->{$var}
ABresult
0X0
100
111
83 0 $self->{_REGISTRY}{_DATA}{$var}{data}=$self->{$var};
84 0 $self->{_REGISTRY}{_DATA}{$var}{prep}=0;
85 0 $self->{$var}=undef;
86 }
87 }
88 }
89 0 $self->{_REGISTRY}{$package}{prep}=1;
90 0 $self->{_REGISTRY}{ref($self)}{prep}=1;
91 0 $self->_clean($package);
92 }
93  
94 0 ▶sub _taint { # Marks a namespace as untied from the back-end database
Subroutine _taint: not called CC=5 SCAR=34.0
95 # Intended to be called on destruction only
96 0 my $self=shift;
97 0 ▶ my $package=shift || caller;
Condition0%0/3
shift() || caller
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || caller
shift() caller
Truth table0%0/3
A || B
A= shift()B= caller
ABresult
1X1
011
000
98 0 $self->_dirty($package);
99 0 ▶ (my @vars=$self->_vars($package)) || return $self;
Branch: 1 branch
BranchTrueFalseTotal
my(@vars) = $self->_vars($package) or return $self 0 0 0
100 0 foreach my $var (@vars) {
101 0 ▶ if ($self->_isobject($var)) { # Reset embedded object information (only if needed)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_isobject($var)) 0 0 0
102 0 $self->{_REGISTRY}{_DATA}{$var}{prep}=0;
103 0 $self->{$var}=undef;
104 }
105 }
106 0 $self->{_REGISTRY}{$package}{prep}=0;
107 }
108  
109 0 ▶sub _clean { # Marks a namespace as in-sync with the back-end database
Subroutine _clean: not called CC=2 SCAR=17.9
110 # Intended to be called on all calls to add(), refresh() and update()
111 0 my $self=shift;
112 0 ▶ my $package=shift || caller;
Condition0%0/3
shift() || caller
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || caller
shift() caller
Truth table0%0/3
A || B
A= shift()B= caller
ABresult
1X1
011
000
113 0 $self->{_REGISTRY}{$package}{dirty}=0;
114 }
115  
116 0 ▶sub _dirty { # Marks a namespace as out-of-sync with the back-end databse
Subroutine _dirty: not called CC=2 SCAR=17.9
117 # Intended to be called upon a write-access call to a class-method
118 0 my $self=shift;
119 0 ▶ my $package=shift || caller;
Condition0%0/3
shift() || caller
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || caller
shift() caller
Truth table0%0/3
A || B
A= shift()B= caller
ABresult
1X1
011
000
120 0 $self->{_REGISTRY}{$package}{dirty}=1;
121 }
122  
123 0 ▶sub _vars { # Returns a list of variables registered to a specific namespace
Subroutine _vars: not called CC=4 SCAR=30.0
124 # Used internally by default _refresh() and update() methods
125 0 my $self=shift;
126 0 ▶ my $package=shift || caller;
Condition0%0/3
shift() || caller
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || caller
shift() caller
Truth table0%0/3
A || B
A= shift()B= caller
ABresult
1X1
011
000
127 0 my @vars = ();
128 0 my @keys = keys(%{$self->{_REGISTRY}{_DATA}});
129 0 foreach my $var(@keys) {
130 0 ▶ push @vars,$var if ($self->{_REGISTRY}{_DATA}{$var}{source} eq $package);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_REGISTRY"}{"_DATA"}{$var}{"source"} eq $package 0 0 0
131 }
132 0 return @vars;
133 }
134  
135 0 ▶sub _refresh { # Default back-end for refresh
Subroutine _refresh: not called CC=7 SCAR=37.5
136 # Inherited classes should implement a custom _refresh()
137 # Alternatively, the default _refresh may be used if a valid DBI connection
138 # is set using $__PACKAGE__::dbh and the table is set to $__PACKAGE__::table
139 0 my $self=shift;
140 0 ▶ my $package=(UNIVERSAL::isa($_[0],__PACKAGE__) && shift) || ref($self);
Condition0%0/6
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || ref $self
l!l&&r!l&&!r
000
UNIVERSAL::isa($_[0], __PACKAGE__) and shift()
!ll&&!rl&&r
000
MC/DC0%0/3
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || ref $self
UNIVERSAL::isa($_[0], __PACKAGE__) shift() ref $self
Truth table0%0/5
A and B || C
A= UNIVERSAL::isa($_[0], __PACKAGE__)B= shift()C= ref $self
ABCresult
11X1
0X11
1011
0X00
1000
141 0 ▶ my @vars=$self->_vars($package) || return $self;
Condition0%0/2
$self->_vars($package) || (return $self)
l!l
00
MC/DC0%0/1
$self->_vars($package) || (return $self)
$self->_vars($package)
Truth table0%0/2
A
A= $self->_vars($package)
Aresult
11
00
142 0 my $sth;
143 {
144 0 ▶ no strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.2
145 0 eval "\$sth=\$dbh->prepare_cached('SELECT \@vars FROM \$table WHERE (ID=?)');";
146 }
147 0 ▶ $sth->execute(@_) or return $self->blank;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@_) or return $self->blank 0 0 0
148 0 ▶ if ($sth->rows!=1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->rows != 1) { } 0 0 0
149 0 $self->blank;
150 } else {
151 0 my $res=$sth->fetchrow_hashref;
152 0 foreach my $var (@vars) {
153 0 $self->{$var}=$res->{$var};
154 }
155 0 $self->_validate;
156 }
157 0 $sth->finish;
158 0 return $self;
159 }
160  
161 0 ▶sub AUTOLOAD { # Default method call handler
Subroutine AUTOLOAD: not called CC=15 SCAR=53.4
162 # Current support:
163 # * Read/Write registered methods from internal hash
164 0 my $param;
165 my $package;
166 {
167 0 ▶ no strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.2
168 0 $AUTOLOAD=~s/(.*):://;
169 0 $package=$1;
170 0 $param=$AUTOLOAD;
171 }
172 0 ▶ if (UNIVERSAL::isa($_[0],__PACKAGE__)) { # Method call of a sub-class
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_[0], __PACKAGE__)) 0 0 0
173 0 my $self=shift;
174 0 ▶ if ($self->{_REGISTRY}{_DATA}{uc($param)}) { # Acceptable function call
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_REGISTRY"}{"_DATA"}{uc $param}) 0 0 0
175 0 my $source=$self->{_REGISTRY}{_DATA}{uc($param)}{source};
176 0 ▶ if (!($self->valid($source))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->valid($source)) 0 0 0
177 0 $self->refresh($source);
178 }
179 # SET access
180 0 ▶ if ((@_) && !($self->_readonly($source,$param))) { # Update rewriteable request
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and not $self->_readonly($source, $param)) 0 0 0
Condition0%0/3
@_ and not $self->_readonly($source, $param)
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and not $self->_readonly($source, $param)
@_ not $self->_readonly($source, $param)
Truth table0%0/3
A and not(B)
A= @_B= not $self->_readonly($source, $param)
ABresult
0X0
100
111
181 0 ▶ if ($self->_isbasic($param)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_isbasic($param)) { } 0 0 0
elsif ($self->_isobject($param)) { } 0 0 0
182 0 $self->{uc($param)}=@_;
183 0 $self->_taint;
184 } elsif ($self->_isobject($param)) { # Object SET
185 0 ▶ unless ($self->_isobjarray($param)) { # No SET allowed on arrays
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_isobjarray($param)) 0 0 0
186 0 my ($temp,$pid)=@_;
187 0 ▶ if (ref($temp) eq $self->{_REGISTRY}{_DATA}{uc($param)}{class}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $temp eq $self->{'_REGISTRY'}{'_DATA'}{uc $param}{'class'}) { } 0 0 0
188 # TODO: see if temp->isa($self->{_REGISTRY}{_DATA}{uc($param)}{class})
189 0 $pid=$temp->id; #Retrieve ID from internal object
190 } else {
191 0 $pid=$temp; #Assume ID is specified if not compatible object
192 }
193 0 $self->{_REGISTRY}{_DATA}{uc($param)}{data}=$pid;
194 0 $self->_taint;
195 }
196 }
197 } # GET access
198 0 ▶ if ($self->_isobject($param)) { # Prepare object
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_isobject($param)) 0 0 0
199 0 ▶ return (wantarray?undef:0) unless $self->_o_prep($param);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->_o_prep($param) 0 0 0
wantarray ? : 0 0 0
200 }
201 0 ▶ if ($self->_isobjarray($param)) { # Object array returns special values
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_isobjarray($param)) { } 0 0 0
202 0 ▶ return (wantarray?@{$self->{uc($param)}}:$self->{_REGISTRY}{_DATA}{uc($param)}{prep});
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
203 } else {
204 0 return $self->{uc($param)};
205 }
206 }
207 }
208 }
209  
210 0 ▶sub new { # Default constructor
Subroutine new: not called CC=4 SCAR=30.0
211 # Do not overload this unless you're SURE you know what you're doing
212 0 my $self={ };
213 0 my $proto=shift;
214 0 ▶ my $class=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
215 0 bless $self,$class;
216 0 eval "foreach \$_ (\@".$class."::ISA) {eval \$_.\"::blank(\\\$self);\";}";
217 0 $self->_register;
218 0 $self->blank(@_);
219 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
220 0 ▶ eval ($self->_primary."::_refresh(\$self,'".$self->_primary."',@_);") if ($self->_primary);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_primary 0 0 0
221 0 $self->_refresh(@_);
222 }
223 0 return $self;
224 }
225  
226 0 ▶sub clean { # Returns true if namepace is in-sync with back-end database
Subroutine clean: not called CC=2 SCAR=17.9
227 # Be sure to check for valid()ity BEFORE using this
228 0 my $self=shift;
229 0 ▶ my $package=shift || caller;
Condition0%0/3
shift() || caller
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || caller
shift() caller
Truth table0%0/3
A || B
A= shift()B= caller
ABresult
1X1
011
000
230 0 return !($self->{_REGISTRY}{$package}{dirty});
231 }
232  
233 0 ▶sub valid { # Returns true if namespace is tied and in-sync with back-end database
Subroutine valid: not called CC=7 SCAR=40.3
234 0 my $self=shift;
235 0 ▶ my $package=shift || ref($self);
Condition0%0/3
shift() || ref $self
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || ref $self
shift() ref $self
Truth table0%0/3
A || B
A= shift()B= ref $self
ABresult
1X1
011
000
236 0 ▶ if ($self->_primary)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_primary) { } 0 0 0
237 {return ($self->{_REGISTRY}{$self->_primary}{prep} &&
238 $self->clean($self->_primary) &&
239 $self->{_REGISTRY}{$package}{prep} &&
240 0 ▶ $self->clean($package))}
Condition0%0/9
$self->{'_REGISTRY'}{$self->_primary}{'prep'} && $self->clean($self->_primary) && $self->{'_REGISTRY'}{$package}{'prep'} && $self->clean($package)
!ll&&!rl&&r
000
$self->{"_REGISTRY"}{$self->_primary}{"prep"} and $self->clean($self->_primary) and $self->{"_REGISTRY"}{$package}{"prep"}
!ll&&!rl&&r
000
$self->{"_REGISTRY"}{$self->_primary}{"prep"} and $self->clean($self->_primary)
!ll&&!rl&&r
000
MC/DC0%0/4
$self->{'_REGISTRY'}{$self->_primary}{'prep'} && $self->clean($self->_primary) && $self->{'_REGISTRY'}{$package}{'prep'} && $self->clean($package)
$self->{"_REGISTRY"}{$self->_primary}{"prep"} $self->clean($self->_primary) $self->{"_REGISTRY"}{$package}{"prep"} $self->clean($package)
Truth table0%0/5
A and B and C && D
A= $self->{"_REGISTRY"}{$self->_primary}{"prep"}B= $self->clean($self->_primary)C= $self->{"_REGISTRY"}{$package}{"prep"}D= $self->clean($package)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
241 else {return $self->{_REGISTRY}{$package}{prep} &&
242 0 ▶ $self->clean($package)};
Condition0%0/3
$self->{'_REGISTRY'}{$package}{'prep'} && $self->clean($package)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{'_REGISTRY'}{$package}{'prep'} && $self->clean($package)
$self->{'_REGISTRY'}{$package}{'prep'} $self->clean($package)
Truth table0%0/3
A && B
A= $self->{'_REGISTRY'}{$package}{'prep'}B= $self->clean($package)
ABresult
0X0
100
111
243 }
244  
245 0 ▶sub blank { # Default (abstract) blank method - used by the default constructor
Subroutine blank: not called CC=1 SCAR=6.9
246 # This should be overridden by any inherited class that's meant to be useful
247 # A typical blank() method should look like:
248 # sub blank {
249 # my $self=shift;
250 # $self->_register;
251 # $self->_blank("FOO", "BAR", ... , "LAST");
252 # }
253 0 $_[0]->_register;
254 }
255  
256 0 ▶sub refresh { # Default front-end for refresh
Subroutine refresh: not called CC=2 SCAR=17.9
257 0 my $self=shift;
258 0 ▶ my $package=shift || ref($self);
Condition0%0/3
shift() || ref $self
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || ref $self
shift() ref $self
Truth table0%0/3
A || B
A= shift()B= ref $self
ABresult
1X1
011
000
259 0 $self->_taint($package);
260 0 eval $package."::_refresh(\$self,".$self->id.");";
261 0 return $self->valid;
262 }
263  
264 0 ▶sub id { # Default id method - must be explicitly so that it can be overloaded
Subroutine id: not called CC=3 SCAR=24.8
265 # when needed for refresh, but not be dependant on the object being valid
266 0 my $self=shift;
267 # Set access
268 0 ▶ if ((@_) && !($self->_readonly("id"))) { # Update rewriteable request
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and not $self->_readonly("id")) 0 0 0
Condition0%0/3
@_ and not $self->_readonly("id")
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and not $self->_readonly("id")
@_ not $self->_readonly("id")
Truth table0%0/3
A and not(B)
A= @_B= not $self->_readonly("id")
ABresult
0X0
100
111
269 0 $self->{ID}=@_;
270 0 $self->_taint;
271 }
272 0 return $self->{ID};
273 }
274  
275 0 ▶sub _isbasic { # Returns true if access method marked as basic (default)
Subroutine _isbasic: not called CC=1 SCAR=6.9
276 0 my $self=shift;
277 0 my $var=uc(shift);
278 0 return ($self->{_REGISTRY}{_DATA}{$var}{type} eq "basic");
279 }
280  
281 0 ▶sub _isobject { # Returns true if access method marked as embedded object
Subroutine _isobject: not called CC=1 SCAR=6.9
282 0 my $self=shift;
283 0 my $var=uc(shift);
284 0 return ($self->{_REGISTRY}{_DATA}{$var}{type} eq "object");
285 }
286  
287 0 ▶sub _isobjarray {
Subroutine _isobjarray: not called CC=2 SCAR=17.9
288 0 my $self=shift;
289 0 my $var=uc(shift);
290 0 ▶ return ($self->_isobject($var) && $self->{_REGISTRY}{_DATA}{$var}{array});
Condition0%0/3
$self->_isobject($var) && $self->{'_REGISTRY'}{'_DATA'}{$var}{'array'}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_isobject($var) && $self->{'_REGISTRY'}{'_DATA'}{$var}{'array'}
$self->_isobject($var) $self->{'_REGISTRY'}{'_DATA'}{$var}{'array'}
Truth table0%0/3
A && B
A= $self->_isobject($var)B= $self->{'_REGISTRY'}{'_DATA'}{$var}{'array'}
ABresult
0X0
100
111
291 }
292  
293 0 ▶sub _object { # Marks an access member as an object (call in blank)
Subroutine _object: not called CC=4 SCAR=30.0
294 0 my $self=shift;
295 0 my $var=uc(shift);
296 0 ▶ my $package=(UNIVERSAL::isa($_[0],__PACKAGE__) && shift) || ref($self);
Condition0%0/6
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || ref $self
l!l&&r!l&&!r
000
UNIVERSAL::isa($_[0], __PACKAGE__) and shift()
!ll&&!rl&&r
000
MC/DC0%0/3
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || ref $self
UNIVERSAL::isa($_[0], __PACKAGE__) shift() ref $self
Truth table0%0/5
A and B || C
A= UNIVERSAL::isa($_[0], __PACKAGE__)B= shift()C= ref $self
ABCresult
11X1
0X11
1011
0X00
1000
297 0 $self->{_REGISTRY}{_DATA}{$var}{prep}=0;
298 0 $self->{_REGISTRY}{_DATA}{$var}{class}=$package;
299 0 ▶ $self->{_REGISTRY}{_DATA}{$var}{data}=$self->{$var} || undef;
Condition0%0/2
$self->{$var} || undef
l!l
00
MC/DC0%0/1
$self->{$var} || undef
$self->{$var}
Truth table0%0/2
A
A= $self->{$var}
Aresult
11
00
300 0 $self->{_REGISTRY}{_DATA}{$var}{array}=0;
301 0 $self->{_REGISTRY}{_DATA}{$var}{type}="object";
302 0 $self->{$var}=undef;
303 }
304  
305 0 ▶sub _objarray { # Marks an access member as an array of objects (call in blank)
Subroutine _objarray: not called CC=3 SCAR=24.8
306 0 my $self=shift;
307 0 my $var=uc(shift);
308 0 ▶ my $package=(UNIVERSAL::isa($_[0],__PACKAGE__) && shift) || ref($self);
Condition0%0/6
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || ref $self
l!l&&r!l&&!r
000
UNIVERSAL::isa($_[0], __PACKAGE__) and shift()
!ll&&!rl&&r
000
MC/DC0%0/3
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || ref $self
UNIVERSAL::isa($_[0], __PACKAGE__) shift() ref $self
Truth table0%0/5
A and B || C
A= UNIVERSAL::isa($_[0], __PACKAGE__)B= shift()C= ref $self
ABCresult
11X1
0X11
1011
0X00
1000
309 0 $self->_object($var,$package);
310 0 $self->_readonly($var,1);
311 0 $self->{_REGISTRY}{_DATA}{$var}{array}=1;
312 }
313  
314 # This (objarray) won't be fully implemented until I can figure out how the heck
315 # to set the data source as an array - it probably has to be dealt with by
316 # end-module's refresh ($self->{$var}=@arrayofdata;) [UPDATE VALIDATE TO DEAL WITH THIS]...
317  
318 0 ▶sub _o_prep {
Subroutine _o_prep: not called CC=6 SCAR=37.4
319 0 my $self=shift;
320 0 my $var=uc(shift);
321 0 my $class=$self->{_REGISTRY}{_DATA}{$var}{class};
322 0 my $source=$self->{_REGISTRY}{_DATA}{$var}{source};
323 0 ▶ return 0 unless $self->valid($source);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->valid($source) 0 0 0
324 return $self->{_REGISTRY}{_DATA}{$var}{prep} if
325 0 ▶ $self->{_REGISTRY}{_DATA}{$var}{prep};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_REGISTRY"}{"_DATA"}{$var}{"prep"} 0 0 0
326 0 ▶ if ($self->_isobjarray($var)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_isobjarray($var)) { } 0 0 0
327 0 ▶ for (my $i=0;$i<=$#{$self->{_REGISTRY}{_DATA}{$var}{data}};$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$$self{"_REGISTRY"}{"_DATA"}{$var}{"data"};}) 0 0 0
328 0 $self->{$var}[$i]=$class->new($self->{_REGISTRY}{_DATA}{$var}{data}[$i]);
329 }
330 0 $self->{_REGISTRY}{_DATA}{$var}{prep}=$#{$self->{_REGISTRY}{_DATA}{$var}{data}}+1;
331 } else {
332 0 ▶ $self->{_REGISTRY}{_DATA}{$var}{prep}=(($self->{$var}=$class->new($self->{_REGISTRY}{_DATA}{$var}{data}))?1:0);
Branch: 1 branch
BranchTrueFalseTotal
($self->{$var} = $class->new($self->{'_REGISTRY'}{'_DATA'}{$var}{'data'})) ? : 0 0 0
333 }
334 0 return $self->{_REGISTRY}{_DATA}{$var}{prep};
335 }
336  
337 # TODO: Update updates recursively (into embedded objects)
338 # UpdateNR updates non-0recursively (data ghets lost)
339  
340 # DOCUMENT: _validate also initializes objects by setting internal DATA value and clearing external value
341  
342  
343 package DBIx::Object::DBI; #Shortcut functions for DBI-based backend
344  
345 1 our @ISA=qw(DBIx::Object);
346  
347 0 ▶sub blank {
Subroutine blank: not called CC=1 SCAR=6.9
348 0 $_[0]->_register;
349 }
350  
351 0 ▶sub _dbidbh { # Sets/returns the DBI connection to use
Subroutine _dbidbh: not called CC=4 SCAR=30.0
352 0 my $self=shift;
353 0 ▶ my $package=(UNIVERSAL::isa($_[0],__PACKAGE__) && shift) || caller;
Condition0%0/6
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || caller
l!l&&r!l&&!r
000
UNIVERSAL::isa($_[0], __PACKAGE__) and shift()
!ll&&!rl&&r
000
MC/DC0%0/3
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || caller
UNIVERSAL::isa($_[0], __PACKAGE__) shift() caller
Truth table0%0/5
A and B || C
A= UNIVERSAL::isa($_[0], __PACKAGE__)B= shift()C= caller
ABCresult
11X1
0X11
1011
0X00
1000
354 0 ▶ if($_[0]) {$self->{_REGISTRY}{$package}{DBI}{dbh}=$_[0];}
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) 0 0 0
355 0 return $self->{_REGISTRY}{$package}{DBI}{dbh};
356 }
357  
358 0 ▶sub _dbirefresh { # Sets/returns the SQL statement to run on refresh calls
Subroutine _dbirefresh: not called CC=4 SCAR=30.0
359 0 my $self=shift;
360 0 ▶ my $package=(UNIVERSAL::isa($_[0],__PACKAGE__) && shift) || caller;
Condition0%0/6
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || caller
l!l&&r!l&&!r
000
UNIVERSAL::isa($_[0], __PACKAGE__) and shift()
!ll&&!rl&&r
000
MC/DC0%0/3
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || caller
UNIVERSAL::isa($_[0], __PACKAGE__) shift() caller
Truth table0%0/5
A and B || C
A= UNIVERSAL::isa($_[0], __PACKAGE__)B= shift()C= caller
ABCresult
11X1
0X11
1011
0X00
1000
361 0 ▶ if($_[0]) {$self->{_REGISTRY}{$package}{DBI}{refresh}=$_[0];}
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) 0 0 0
362 0 return $self->{_REGISTRY}{$package}{DBI}{refresh};
363 }
364  
365 0 ▶sub _refresh { # Default back-end for DBI refresh
Subroutine _refresh: not called CC=6 SCAR=37.4
366 # Inherited classes may implement a custom _refresh()
367 0 my $self=shift;
368 0 ▶ my $package=(UNIVERSAL::isa($_[0],__PACKAGE__) && shift) || ref($self);
Condition0%0/6
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || ref $self
l!l&&r!l&&!r
000
UNIVERSAL::isa($_[0], __PACKAGE__) and shift()
!ll&&!rl&&r
000
MC/DC0%0/3
UNIVERSAL::isa($_[0], __PACKAGE__) && shift() || ref $self
UNIVERSAL::isa($_[0], __PACKAGE__) shift() ref $self
Truth table0%0/5
A and B || C
A= UNIVERSAL::isa($_[0], __PACKAGE__)B= shift()C= ref $self
ABCresult
11X1
0X11
1011
0X00
1000
369 0 my $sth=$self->{_REGISTRY}{$package}{DBI}{dbh}->prepare_cached($self->{_REGISTRY}{$package}{DBI}{refresh});
370 0 ▶ $sth->execute(@_) or return $self->blank;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@_) or return $self->blank 0 0 0
371 0 ▶ if ($sth->rows!=1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->rows != 1) { } 0 0 0
372 0 $self->blank;
373 } else {
374 0 my $res=$sth->fetchrow_hashref;
375 0 foreach my $key (keys %{$res}) {
376 0 $self->{uc($key)}=$res->{$key};
377 }
378 0 $self->_validate($package);
379 }
380 0 $sth->finish;
381 0 return $self;
382 }
383  
384 1 1;
385  
386 __END__
↑ Summary