Base.pm

filter: Statementstmt 75.4% 172 / 228 Branchbran 48.7% 40 / 82 Conditioncond 28.0% 16 / 57 MC/DCmcdc 5.8% 2 / 34 Subroutinesub 81.0% 30 / 37 Podpod 0.0% 0 / 3 totaltotal 58.9% 260 / 441 CC 84 SCAR 25.3
CC
84
Cov
62%
attributes
21.9
attr1
21.2
attr1
21.2
CRAP 12.6
« Exception.pm ↑ Summary
1 package Object::Base;
2 =head1 NAME
3  
4 Object::Base - Multi-threaded base class to establish a class deriving relationship with parent classes
5  
6 =head1 VERSION
7  
8 version 1.14
9  
10 =head1 ABSTRACT
11  
12 Multi-threaded base class to establish a class deriving relationship with parent classes
13  
14 package Foo;
15 use Object::Base;
16 attributes ':shared', 'attr1', 'attr2';
17 #
18 package Bar;
19 use Object::Base 'Foo';
20 my $attr3_def = 6;
21 my $attr3_val;
22 attributes ':shared' => undef, 'attr2' => undef, ':lazy',
23 'attr3' => {
24 'default' => sub {
25 my ($self, $key) = @_;
26 print "> default key=$key\n";
27 $attr3_val = $attr3_def-1;
28 return $attr3_def;
29 },
30 'getter' => sub {
31 my ($self, $key) = @_;
32 print "> getter key=$key\n";
33 return $attr3_val+1;
34 },
35 'setter' => sub {
36 my ($self, $key, $value) = @_;
37 print "> setter key=$key value=$value\n";
38 $attr3_val = $value-1;
39 },
40 }
41 ;
42 #
43 package main;
44 use threads;
45 use threads::shared;
46 #
47 # object of Foo
48 my $foo = Foo->new();
49 #
50 # special attribute ':shared'
51 print "\$foo is ", is_shared($foo)? "shared": "not shared", "\n";
52 #
53 # usage of attribute
54 $foo->attr1(1);
55 print $foo->attr1, "\n"; # prints '1'
56 #
57 # attributes are lvalued
58 $foo->attr1++;
59 print $foo->attr1, "\n"; # prints '2'
60 #
61 # assigning ref values to shared class attributes
62 eval { $foo->attr2 = { key1 => 'val1' } }; print "Eval: $@"; # prints error 'Eval: Invalid value for shared scalar at ...'
63 $foo->attr2({ key2 => 'val2' }); # uses shared_clone assigning ref value
64 print $foo->attr2->{key2}, "\n"; # prints 'val2'
65 #
66 # object of derived class Bar
67 my $bar = Bar->new();
68 #
69 # features are overridable
70 print "\$bar is ", is_shared($bar)? "shared": "not shared", "\n"; # prints '$bar is not shared'
71 #
72 # attributes can be added derived classes
73 # attributes can have modifiers: default
74 print "attr3 default value is ", $bar->attr3, "\n"; # prints 'attr3 default value is 6'
75 #
76 # attributes can have modifiers: setter
77 $bar->attr3 = 3;
78 print "attr3 set", "\n";
79 #
80 # attributes can have modifiers: getter
81 print "attr3 value ", $bar->attr3, " and stored as $attr3_val", "\n"; # prints 'attr3 value 3 and stored as 2'
82 #
83 # attributes are inheritable
84 $bar->attr1(3);
85 #
86 # attributes are overridable
87 eval { $bar->attr2 = 4 }; print "Eval: $@"; # prints error 'Eval: Attribute attr2 is not defined in Bar at ...'
88 #
89 # attributes in thread
90 my $thr1 = threads->create(sub { $foo->attr1 = 5; $bar->attr1 = 5; });
91 my $thr2 = threads->create(sub { sleep 1; print "\$foo is shared and attr1: ", $foo->attr1, ", \$bar is not shared and attr1: ", $bar->attr1, "\n"; });
92 # prints '$foo is shared and attr1: 5, $bar is not shared and attr1: 3'
93 $thr1->join();
94 $thr2->join();
95  
96 =head1 DESCRIPTION
97  
98 Object::Base provides blessed and thread-shared(with :shared feature) object with in B<new> method. B<new> method
99 can be used as a constructor and overridable in derived classes. B<new()> should be called in derived class
100 constructors to create and bless self-object.
101  
102 Derived classes own package automatically uses threads, threads::shared, strict, warnings with using Object::Base. If
103 Perl is not built to support threads; it uses forks, forks::shared instead of threads, threads::shared. Object::Base
104 should be loaded as first module.
105  
106 Import parameters of Object::Base, define parent classes of derived class.
107 If none of parent classes derived from Object::Base or any parent isn't defined, Object::Base is automatically added
108 in parent classes.
109  
110 =head2 Attributes
111  
112 Attributes define read-write accessors binded value of same named key in objects own hash if attribute names is
113 valid subroutine identifiers. Otherwise, attribute defines B<feature> to get new features into class.
114  
115 Attributes;
116  
117 =over
118  
119 =item *
120  
121 Lvaluable
122  
123 =item *
124  
125 Inheritable
126  
127 =item *
128  
129 Overridable
130  
131 =item *
132  
133 Redefinable
134  
135 =back
136  
137 =head3 Modifiers
138  
139 Attributes can have their own modifiers in hash reference at definition. Attribute modifiers don't work with ':shared' feature.
140  
141 =head4 default
142  
143 getter method of default value of attribute, otherwise value is default value
144  
145 attributes
146 'attr1' => {
147 'default' => sub {
148 my ($self, $key) = @_;
149 return "default value of $key";
150 },
151 },
152 'attr2' => {
153 'default' => "default value of attr2",
154 };
155  
156 =head4 getter
157  
158 getter method of attribute
159  
160 my $attr1_val;
161 attributes
162 'attr1' => {
163 'getter' => sub {
164 my ($self, $key) = @_;
165 return $attr1_val;
166 },
167 };
168  
169 =head4 setter
170  
171 setter method of attribute
172  
173 my $attr1_val;
174 attributes
175 'attr1' => {
176 'setter' => sub {
177 my ($self, $key, $value) = @_;
178 $attr1_val = $value;
179 },
180 };
181  
182 =head3 Features
183  
184 =head4 :shared
185  
186 Class will be craated as thread-shared. But attribute modifiers don't work with ':shared' feature.
187  
188 =head4 :lazy
189  
190 Attributes will be initialized with default values using default modifier at first fetching or storing instead of object construction with new().
191  
192 =cut
193 BEGIN
194 3 ▶{
Subroutine BEGIN: called CC=2 SCAR=6.9
195 3 require Config;
196 3 ▶ if ($Config::Config{'useithreads'})
Branch: 1 branch
BranchTrueFalseTotal
if ($Config::Config{'useithreads'}) { } 1 2 3
197 {
198 1 require threads;
199 1 threads->import();
200 1 require threads::shared;
201 1 threads::shared->import();
202 } else
203 {
204 2 require forks;
205 1 forks->import();
206 1 require forks::shared;
207 1 forks::shared->import();
208 }
209 }
210 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
211 2 ▶no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
212 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
213  
214  
215 BEGIN
216 2 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
217 2 require 5.008;
218 2 $Object::Base::VERSION = '1.14';
219 2 $Object::Base::ISA = ();
220 }
221  
222  
223 2 my $package = __PACKAGE__;
224 2 my $context = $package;
225 2 $context =~ s/\Q::\E//g;
226  
227  
228 sub import
229 3 ▶{
Subroutine import: called CC=9 SCAR=23.7
230 3 ▶ die "$package can not be imported at run-time" if ${^GLOBAL_PHASE} eq "RUN";
Branch: 1 branch
BranchTrueFalseTotal
if ${^GLOBAL_PHASE} eq "RUN" 0 3 3
231 3 my $importer = shift;
232 3 my $caller = caller;
233 3 ▶ return unless $importer eq $package;
Branch: 1 branch
BranchTrueFalseTotal
unless $importer eq $package 0 3 3
234 eval join "\n",
235 "package $caller;",
236 << "EOF",
237 BEGIN
238 {
239 require Config;
240 if (\$Config::Config{'useithreads'})
241 {
242 require threads;
243 threads->import();
244 require threads::shared;
245 threads::shared->import();
246 } else
247 {
248 require forks;
249 forks->import();
250 require forks::shared;
251 forks::shared->import();
252 }
253 }
254 use SUPER;
255 EOF
256 "use strict;",
257 "use warnings;",
258 "",
259 3 (exists(&{"${caller}::attributes"})? "": "sub attributes { ${package}::attributes(\@_) }"),
260 "",
261 "\%${caller}::${context} = () unless defined(\\\%${caller}::${context});",
262 "",
263 (
264 map {
265 0 ▶ my $p = (defined and not ref)? $_: "";
Subroutine BEGIN: called CC=2 SCAR=7.3
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=2 SCAR=7.3
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine attributes: called CC=1 SCAR=0.2
Subroutine attributes: called CC=1 SCAR=0.2
Branch: 4 branches
BranchTrueFalseTotal
if ($Config::Config{'useithreads'}) { } 2 0 2
if ($Config::Config{'useithreads'}) { } 1 0 1
exists &{"${caller}::attributes";} ? : 0 3 3
defined $_ && !ref($_) ? : 2 0 2
Condition33%1/3
defined $_ and not ref $_
!ll&&!rl&&r
002
MC/DC0%0/2
defined $_ and not ref $_
defined $_ not ref $_
Truth table33%1/3
A and not(B)
A= defined $_B= not ref $_
ABresult
0X0
100
111
266 2 ▶ $p and /^[^\W\d]\w*(\:\:[^\W\d]\w*)*\z/s or die "Invalid base-class name $p";
Branch: 1 branch
BranchTrueFalseTotal
$p and /^[^\W\d]\w*(\:\:[^\W\d]\w*)*\z/s or die "Invalid base-class name $p" 2 0 2
Condition33%1/3
$p and /^[^\W\d]\w*(\:\:[^\W\d]\w*)*\z/s
!ll&&!rl&&r
002
MC/DC0%0/2
$p and /^[^\W\d]\w*(\:\:[^\W\d]\w*)*\z/s
$p /^[^\W\d]\w*(\:\:[^\W\d]\w*)*\z/s
Truth table33%1/3
A and B
A= $pB= /^[^\W\d]\w*(\:\:[^\W\d]\w*)*\z/s
ABresult
0X0
100
111
267 2 << "EOF";
268 eval { require $_ };
269 push \@${caller}::ISA, '$_';
270 if ($_->isa('$package'))
271 {
272 \$${caller}::${context}{\$_} = \$$_\::${context}{\$_} for (keys \%$_\::${context});
273 }
274 EOF
275 } @_
276 ),
277 "push \@${caller}::ISA, '$package' unless UNIVERSAL::isa('${caller}', '$package');";
278 3 ▶ die "Failed to import $package in $caller: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
279 3 return 1;
280 }
281  
282 sub attributes
283 3 ▶{
Subroutine attributes: called CC=10 SCAR=30.9
Pod undocumented
284 3 my $caller = caller;
285 3 ▶ die "$caller is not $package class" unless UNIVERSAL::isa($caller, $package);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($caller, $package) 0 3 3
286 0 ▶ %{"${caller}::${context}"} = () unless defined(\%{"${caller}::${context}"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined \%{"${caller}::$context";} 0 3 3
287 3 my $l;
288 3 for (@_)
289 {
290 12 ▶ if (not defined($_) or ref($_))
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_ or ref $_) 2 10 12
Condition66%2/3
not defined $_ or ref $_
l!l&&r!l&&!r
2010
MC/DC50%1/2
not defined $_ or ref $_
not defined $_ ref $_
Truth table66%2/3
not(A) or B
A= not defined $_B= ref $_
ABresult
1X1
011
000
291 {
292 2 ▶ next if not defined($l) or ref($l);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $l or ref $l 0 2 2
Condition33%1/3
not defined $l or ref $l
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined $l or ref $l
not defined $l ref $l
Truth table33%1/3
not(A) or B
A= not defined $lB= ref $l
ABresult
1X1
011
000
293 2 ${"${caller}::${context}"}{$l} = $_;
294 2 next;
295 }
296 10 ${"${caller}::${context}"}{$_} = {};
297 } continue
298 {
299 12 $l = $_;
300 }
301 eval join "\n",
302 "package $caller;",
303 "",
304 map {
305 6 << "EOF";
306 sub $_ :lvalue
307 {
308 my \$self = shift;
309 die 'Attribute $_ is not defined in $caller' unless \$${caller}::${context}{"$_"};
310 die 'Object is not derived from $package' unless defined(\$self) and UNIVERSAL::isa(ref(\$self), '$package');
311 my \@args = \@_;
312 if (\@args >= 1)
313 {
314 unless (is_shared(%{\$self}) and ref(\$args[0]) and not is_shared(\$args[0]))
315 {
316 \$self->{"$_"} = \$args[0];
317 } else
318 {
319 \$self->{"$_"} = shared_clone(\$args[0]);
320 }
321 }
322 \$self->{"$_"};
323 }
324 EOF
325 0 ▶ } grep { /^[^\W\d]\w*\z/s and not exists(&{"${caller}::$_"}) } keys %{"${caller}::${context}"};
Subroutine attr1: called CC=8 SCAR=30.5
Subroutine attr1: called CC=8 SCAR=30.5
Subroutine attr2: called CC=8 SCAR=30.5
Pod undocumented
Branch: 12 branches
BranchTrueFalseTotal
unless $Foo::ObjectBase{"attr1"} 0 3 3
unless defined $self and UNIVERSAL::isa(ref $self, "Object::Base") 0 3 3
if (@args >= 1) 0 3 3
if (&is_shared(\%{$self;}) and ref $args[0] and not &is_shared(\$args[0])) { } 0 0 0
unless $Bar::ObjectBase{"attr1"} 1 0 1
unless defined $self and UNIVERSAL::isa(ref $self, "Object::Base") 0 0 0
if (@args >= 1) 0 0 0
if (&is_shared(\%{$self;}) and ref $args[0] and not &is_shared(\$args[0])) { } 0 0 0
unless $Foo::ObjectBase{"attr2"} 0 5 5
unless defined $self and UNIVERSAL::isa(ref $self, "Object::Base") 0 5 5
if (@args >= 1) 1 4 5
if (&is_shared(\%{$self;}) and ref $args[0] and not &is_shared(\$args[0])) { } 1 0 1
Condition20%6/30
/^[^\W\d]\w*\z/s && !exists(&{"${caller}::$_";})
!ll&&!rl&&r
406
defined $self and UNIVERSAL::isa(ref $self, "Object::Base")
!ll&&!rl&&r
003
&is_shared(\%{$self;}) and ref $args[0] and not &is_shared(\$args[0])
!ll&&!rl&&r
000
&is_shared(\%{$self;}) and ref $args[0]
!ll&&!rl&&r
000
defined $self and UNIVERSAL::isa(ref $self, "Object::Base")
!ll&&!rl&&r
000
&is_shared(\%{$self;}) and ref $args[0] and not &is_shared(\$args[0])
!ll&&!rl&&r
000
&is_shared(\%{$self;}) and ref $args[0]
!ll&&!rl&&r
000
defined $self and UNIVERSAL::isa(ref $self, "Object::Base")
!ll&&!rl&&r
005
&is_shared(\%{$self;}) and ref $args[0] and not &is_shared(\$args[0])
!ll&&!rl&&r
001
&is_shared(\%{$self;}) and ref $args[0]
!ll&&!rl&&r
001
MC/DC50%1/2
/^[^\W\d]\w*\z/s && !exists(&{"${caller}::$_";})
/^[^\W\d]\w*\z/s !exists(&{"${caller}::$_";})
MC/DC0%0/2
defined $self and UNIVERSAL::isa(ref $self, "Object::Base")
defined $self UNIVERSAL::isa(ref $self, "Object::Base")
MC/DC0%0/3
&is_shared(\%{$self;}) and ref $args[0] and not &is_shared(\$args[0])
&is_shared(\%{$self;}) ref $args[0] not &is_shared(\$args[0])
MC/DC0%0/2
defined $self and UNIVERSAL::isa(ref $self, "Object::Base")
defined $self UNIVERSAL::isa(ref $self, "Object::Base")
MC/DC0%0/3
&is_shared(\%{$self;}) and ref $args[0] and not &is_shared(\$args[0])
&is_shared(\%{$self;}) ref $args[0] not &is_shared(\$args[0])
MC/DC0%0/2
defined $self and UNIVERSAL::isa(ref $self, "Object::Base")
defined $self UNIVERSAL::isa(ref $self, "Object::Base")
MC/DC0%0/3
&is_shared(\%{$self;}) and ref $args[0] and not &is_shared(\$args[0])
&is_shared(\%{$self;}) ref $args[0] not &is_shared(\$args[0])
Truth table66%2/3
A && not(B)
A= /^[^\W\d]\w*\z/sB= !exists(&{"${caller}::$_";})
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= defined $selfB= UNIVERSAL::isa(ref $self, "Object::Base")
ABresult
0X0
100
111
Truth table0%0/4
A and B and not(C)
A= &is_shared(\%{$self;})B= ref $args[0]C= not &is_shared(\$args[0])
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A and B
A= defined $selfB= UNIVERSAL::isa(ref $self, "Object::Base")
ABresult
0X0
100
111
Truth table0%0/4
A and B and not(C)
A= &is_shared(\%{$self;})B= ref $args[0]C= not &is_shared(\$args[0])
ABCresult
0XX0
10X0
1100
1111
Truth table33%1/3
A and B
A= defined $selfB= UNIVERSAL::isa(ref $self, "Object::Base")
ABresult
0X0
100
111
Truth table25%1/4
A and B and not(C)
A= &is_shared(\%{$self;})B= ref $args[0]C= not &is_shared(\$args[0])
ABCresult
0XX0
10X0
1100
1111
326 3 ▶ die "Failed to generate attributes in $caller: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
327 3 return 1;
328 }
329  
330 sub new
331 2 ▶{
Subroutine new: called CC=7 SCAR=20.5
Pod undocumented
332 2 my $class = shift;
333 2 ▶ die "Invalid $package class" unless
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class and not ref $class and UNIVERSAL::isa($class, $package) 0 2 2
Condition33%2/6
defined $class and not ref $class and UNIVERSAL::isa($class, $package)
!ll&&!rl&&r
002
defined $class and not ref $class
!ll&&!rl&&r
002
MC/DC0%0/3
defined $class and not ref $class and UNIVERSAL::isa($class, $package)
defined $class not ref $class UNIVERSAL::isa($class, $package)
Truth table25%1/4
A and not(B) and C
A= defined $classB= not ref $classC= UNIVERSAL::isa($class, $package)
ABCresult
0XX0
10X0
1100
1111
334 defined($class) and
335 not ref($class) and
336 UNIVERSAL::isa($class, $package);
337 2 ▶ die "$package context is not defined" unless defined(\%{"${class}::${context}"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined \%{"${class}::$context";} 0 2 2
338 2 my $self = {};
339 2 ▶ tie %$self, "${package}::TieHash", $class, \$self unless ${"${class}::${context}"}{":shared"};
Branch: 1 branch
BranchTrueFalseTotal
unless do { "${class}::$context" }->{":shared"} 1 1 2
340 2 ▶ $self = shared_clone($self) if ${"${class}::${context}"}{":shared"};
Branch: 1 branch
BranchTrueFalseTotal
if do { "${class}::$context" }->{":shared"} 1 1 2
341 2 bless $self, $class;
342 }
343  
344 sub DESTROY
345 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=0.0
346 }
347  
348  
349 package Object::Base::TieHash;
350 BEGIN
351 2 ▶{
Subroutine BEGIN: called CC=2 SCAR=8.3
352 2 require Config;
353 2 ▶ if ($Config::Config{'useithreads'})
Branch: 1 branch
BranchTrueFalseTotal
if ($Config::Config{'useithreads'}) { } 2 0 2
354 {
355 2 require threads;
356 2 threads->import();
357 2 require threads::shared;
358 2 threads::shared->import();
359 } else
360 {
361 0 require forks;
362 0 forks->import();
363 0 require forks::shared;
364 0 forks::shared->import();
365 }
366 }
367 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
368 2 ▶no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
369 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
370  
371  
372 BEGIN
373 2 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
374 2 require 5.008;
375 2 $Object::Base::TieHash::VERSION = $Object::Base::VERSION;
376 }
377  
378  
379 sub TIEHASH
380 1 ▶{
Subroutine TIEHASH: called CC=3 SCAR=11.0
381 1 my $class = shift;
382 1 my $self = [{}, @_, {}];
383 1 bless $self, $class;
384 1 for (grep /^[^\W\d]\w*\z/s, keys(%{"$self->[1]\::${context}"}))
385 {
386 1 $self->[0]->{$_} = undef;
387 1 ▶ $self->def($_) unless ${"$self->[1]\::${context}"}{":lazy"};
Branch: 1 branch
BranchTrueFalseTotal
unless do { "$self->[1]::$context" }->{":lazy"} 0 1 1
388 }
389 1 $self;
390 }
391  
392 sub STORE
393 2 ▶{
Subroutine STORE: called CC=5 SCAR=20.4
394 2 my $self = shift;
395 2 my ($key, $value) = @_;
396 2 ▶ if ($key =~ /^[^\W\d]\w*\z/s)
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^[^\W\d]\w*\z/s) 2 0 2
397 {
398 2 $self->def($key);
399 2 my $attr = ${"$self->[1]\::${context}"}{$key};
400 2 ▶ if (ref($attr) eq 'HASH' and exists($attr->{"setter"}))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr eq "HASH" and exists $attr->{"setter"}) 0 2 2
Condition33%1/3
ref $attr eq "HASH" and exists $attr->{"setter"}
!ll&&!rl&&r
200
MC/DC0%0/2
ref $attr eq "HASH" and exists $attr->{"setter"}
ref $attr eq "HASH" exists $attr->{"setter"}
Truth table33%1/3
A and B
A= ref $attr eq "HASH"B= exists $attr->{"setter"}
ABresult
0X0
100
111
401 {
402 0 my $setter = $attr->{"setter"};
403 0 ▶ if (ref($setter) eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $setter eq "CODE") 0 0 0
404 {
405 0 $setter->(${$self->[2]}, $key, $value);
406 }
407 }
408 }
409 2 $self->[0]->{$key} = $value;
410 }
411  
412 sub FETCH
413 2 ▶{
Subroutine FETCH: called CC=5 SCAR=20.4
414 2 my $self = shift;
415 2 my ($key) = @_;
416 2 ▶ if ($key =~ /^[^\W\d]\w*\z/s)
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^[^\W\d]\w*\z/s) 2 0 2
417 {
418 2 $self->def($key);
419 2 my $attr = ${"$self->[1]\::${context}"}{$key};
420 2 ▶ if (ref($attr) eq 'HASH' and exists($attr->{"getter"}))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr eq "HASH" and exists $attr->{"getter"}) 0 2 2
Condition33%1/3
ref $attr eq "HASH" and exists $attr->{"getter"}
!ll&&!rl&&r
200
MC/DC0%0/2
ref $attr eq "HASH" and exists $attr->{"getter"}
ref $attr eq "HASH" exists $attr->{"getter"}
Truth table33%1/3
A and B
A= ref $attr eq "HASH"B= exists $attr->{"getter"}
ABresult
0X0
100
111
421 {
422 0 my $getter = $attr->{"getter"};
423 0 ▶ if (ref($getter) eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $getter eq "CODE") 0 0 0
424 {
425 0 $self->[0]->{$key} = $getter->(${$self->[2]}, $key);
426 }
427 }
428 }
429 2 $self->[0]->{$key};
430 }
431  
432 sub EXISTS
433 0 ▶{
Subroutine EXISTS: not called CC=1 SCAR=6.9
434 0 exists $_[0][0]->{$_[1]};
435 }
436  
437 sub DELETE
438 0 ▶{
Subroutine DELETE: not called CC=1 SCAR=6.9
439 0 delete $_[0][$#{$_[0]}]->{$_[1]};
440 0 delete $_[0][0]->{$_[1]};
441 }
442  
443 sub CLEAR
444 0 ▶{
Subroutine CLEAR: not called CC=1 SCAR=6.9
445 0 %{$_[0][$#{$_[0]}]} = ();
446 0 %{$_[0][0]} = ();
447 }
448  
449 sub FIRSTKEY
450 0 ▶{
Subroutine FIRSTKEY: not called CC=1 SCAR=6.9
451 0 my $a = scalar keys %{$_[0][0]};
452 0 each %{$_[0][0]};
453 }
454  
455 sub NEXTKEY
456 0 ▶{
Subroutine NEXTKEY: not called CC=1 SCAR=6.9
457 0 each %{$_[0][0]};
458 }
459  
460 sub SCALAR
461 0 ▶{
Subroutine SCALAR: not called CC=1 SCAR=6.9
462 0 scalar %{$_[0][0]};
463 }
464  
465 sub def
466 4 ▶{
Subroutine def: called CC=5 SCAR=18.4
467 4 my $self = shift;
468 4 my ($key) = @_;
469 4 ▶ unless (exists($self->[$#{$self}]->{$key}))
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$self[$#{$self;}]{$key}) 1 3 4
470 {
471 1 my $val = undef;
472 1 my $attr = ${"$self->[1]\::${context}"}{$key};
473 1 ▶ if (ref($attr) eq 'HASH' and exists($attr->{"default"}))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr eq "HASH" and exists $attr->{"default"}) 0 1 1
Condition33%1/3
ref $attr eq "HASH" and exists $attr->{"default"}
!ll&&!rl&&r
100
MC/DC0%0/2
ref $attr eq "HASH" and exists $attr->{"default"}
ref $attr eq "HASH" exists $attr->{"default"}
Truth table33%1/3
A and B
A= ref $attr eq "HASH"B= exists $attr->{"default"}
ABresult
0X0
100
111
474 {
475 0 my $default = $attr->{"default"};
476 0 ▶ if (ref($default) eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $default eq 'CODE') { } 0 0 0
477 {
478 0 $val = $default->(${$self->[2]}, $key);
479 } else
480 {
481 0 $val = $default;
482 }
483 }
484 1 $self->[$#{$self}]->{$key} = $val;
485 1 $self->[0]->{$key} = $val;
486 }
487 4 return $self->[$#{$self}]->{$key};
488 }
489  
490  
491 2 1;
492 __END__
« Exception.pm ↑ Summary