blib/lib/Object/InsideOut.pm

filter: Statementstmt 78.5% 1253 / 1595 Branchbran 69.6% 671 / 964 Conditioncond 55.2% 159 / 288 MC/DCmcdc 31.2% 54 / 173 Subroutinesub 84.3% 108 / 128 Podpod 24.3% 10 / 41 totaltotal 70.7% 2255 / 3189 SCAR 90.2
CC
629
Cov
73%
CLONE
650.0
create_accessors
383.2
initialize
259.5
CRAP 8274.7
↑ Summary blib/lib/Object/InsideOut/Util.pm »
1 package Object::InsideOut; {
2  
3 44 require 5.006;
4  
5 56 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 54 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 44 our $VERSION = '4.03';
9 44 $VERSION = eval $VERSION;
10  
11 54 ▶use Object::InsideOut::Exception 4.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 54 ▶use Object::InsideOut::Util 4.03 qw(create_object hash_re is_it make_shared);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 52 ▶use Object::InsideOut::Metadata 4.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 44 require B;
16  
17 51 ▶use Scalar::Util 1.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 44 ▶if (! Scalar::Util->can('weaken')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Scalar::Util"->can("weaken")) 6 61 67
19 0 OIO->Trace(0);
20 0 OIO::Code->die(
21 'message' => q/Cannot use 'pure perl' version of Scalar::Util - 'weaken' missing/,
22 'Info' => 'Upgrade/reinstall your version of Scalar::Util');
23 }
24  
25  
26 ### Global Data ###
27  
28 44 my %GBL;
29 44 ▶if (! exists($GBL{'GBL_SET'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $GBL{"GBL_SET"}) 47 12 59
30 44 ▶ %GBL = (
Branch: 1 branch
BranchTrueFalseTotal
$threads::threads ? : 13 55 68
31 'GBL_SET' => 1, # Control flag for initializing this hash
32  
33 %GBL, # Contains 'perm', 'merge', 'attr', 'meta'
34 # from compilation phase
35  
36 init => 1, # Initialization flag
37 # term # Termination flag
38  
39 export => [ # Exported subroutines (i.e., @EXPORT)
40 qw(new clone meta set DESTROY)
41 ],
42  
43 tree => { # Class trees
44 td => {}, # Top down
45 bu => {}, # Bottom up
46 },
47  
48 asi => {}, # Reverse 'isa'
49  
50 id => {
51 obj => {}, # Object IDs
52 reuse => {}, # Reclaimed obj IDs
53 },
54  
55 fld => {
56 ref => {}, # :Field
57 # new
58 type => {}, # :Type
59 weak => {}, # :Weak
60 deep => {}, # :Deep
61 def => {}, # :Default
62  
63 regen => { # Fix field keys during CLONE
64 type => [],
65 weak => [],
66 deep => [],
67 },
68 },
69 hash_only => {}, # :Hash_Only
70  
71 args => {}, # :InitArgs
72  
73 sub => {
74 id => {}, # :ID
75 init => {}, # :Init
76 pre => {}, # :PreInit
77 repl => {}, # :Replicate
78 dest => {}, # :Destroy
79 auto => {}, # :Automethod
80 # cumu # :Cumulative
81 # chain # :Chained
82 # ol # :*ify (overload)
83 },
84  
85 dump => {
86 dumper => {}, # :Dumper
87 pumper => {}, # :Pumper
88 fld => {}, # Field info
89 args => [], # InitArgs info
90 },
91  
92 heritage => {}, # Foreign class inheritance data
93  
94 # Currently executing thread
95 tid => (($threads::threads) ? threads->tid() : 0),
96 # pids # Pseudo-forks
97  
98 obj => {}, # Object registry for thread cloning
99  
100 share => { # Object sharing between threads
101 cl => {},
102 ok => $threads::shared::threads_shared,
103 # obj # Tracks TIDs for shared objects
104 },
105  
106 # cache # Object initialization activity cache
107 );
108  
109 # Add metadata
110 44 $GBL{'meta'}{'add'}{'Object::InsideOut'} = {
111 'import' => {'hidden' => 1},
112 'MODIFY_CODE_ATTRIBUTES' => {'hidden' => 1},
113 'inherit' => {'restricted' => 1},
114 'disinherit' => {'restricted' => 1},
115 'heritage' => {'restricted' => 1},
116 };
117 }
118  
119  
120 ### Import ###
121  
122 # Doesn't export anything - just builds class trees and handles module flags
123 sub import
124 {
125 144 ▶ my $self = shift; # Ourself (i.e., 'Object::InsideOut')
Subroutine import: called CC=34 SCAR=40.6
126 144 ▶ if (Scalar::Util::blessed($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($self)) 0 144 144
127 0 OIO::Method->die('message' => q/'import' called as an object method/);
128 }
129  
130 # Invoked via inheritance - ignore
131 144 ▶ if ($self ne 'Object::InsideOut') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self ne "Object::InsideOut") 0 144 144
132 0 ▶ if (Exporter->can('import')) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Exporter"->can("import")) 0 0 0
133 0 my $lvl = $Exporter::ExportLevel;
134 0 ▶ $Exporter::ExportLevel = (caller() eq 'Object::InsideOut') ? 3 : 1;
Branch: 1 branch
BranchTrueFalseTotal
caller() eq 'Object::InsideOut' ? : 0 0 0
135 0 $self->Exporter::import(@_);
136 0 $Exporter::ExportLevel = $lvl;
137 }
138 0 return;
139 }
140  
141 144 my $class = caller(); # The class that is using us
142 144 ▶ if (! $class || $class eq 'main') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $class or $class eq "main") 0 144 144
Condition33%1/3
not $class or $class eq "main"
l!l&&r!l&&!r
00144
MC/DC0%0/2
not $class or $class eq "main"
not $class $class eq "main"
Truth table33%1/3
not(A) or B
A= not $classB= $class eq "main"
ABresult
1X1
011
000
143 0 OIO::Code->die(
144 'message' => q/'import' invoked from 'main'/,
145 'Info' => "Can't use 'use Object::InsideOut;' or 'Object::InsideOut->import();' inside application code");
146 }
147  
148 47 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
149  
150 # Check for class's global sharing flag
151 # (normally set in the app's main code)
152 144 ▶ if (defined(${$class.'::shared'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined ${$class . '::shared';}) 0 144 144
153 0 set_sharing($class, ${$class.'::shared'}, (caller())[1..2]);
154 }
155  
156 # Check for class's global 'storable' flag
157 # (normally set in the app's main code)
158 {
159 45 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
160 144 ▶ if (${$class.'::storable'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$class . '::storable';}) 0 144 144
161 0 push(@_, 'Storable');
162 }
163 }
164  
165 # Import packages and handle :SHARED flag
166 144 my @packages;
167 144 ▶ while (my $pkg = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pkg = shift()) 100 137 237
168 100 ▶ next if (! $pkg); # Ignore empty strings and such
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg 0 100 100
169  
170 # Handle thread object sharing flag
171 100 ▶ if ($pkg =~ /^:(NOT?_?|!)?SHAR/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg =~ /^:(NOT?_?|!)?SHAR/i) 0 100 100
172 0 ▶ my $sharing = (defined($1)) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 0 0 0
173 0 set_sharing($class, $sharing, (caller())[1..2]);
174 0 next;
175 }
176  
177 # Handle hash fields only flag
178 100 ▶ if ($pkg =~ /^:HASH/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg =~ /^:HASH/i) 3 97 100
179 3 $GBL{'hash_only'}{$class} = [ $class, (caller())[1,2] ];
180 3 next;
181 }
182  
183 # Restricted class
184 97 ▶ if ($pkg =~ /^:RESTRICT(?:ED)?(?:\((.*)\))?/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg =~ /^:RESTRICT(?:ED)?(?:\((.*)\))?/i) 2 95 97
185 2 *{$class.'::new'}
186 = wrap_RESTRICTED($class, 'new',
187 3 ▶ sub { goto &Object::InsideOut::new },
Subroutine __ANON__: called CC=1 SCAR=0.0
188 2 ▶ [ grep {$_} split(/[,'\s]+/, $1 || '') ]);
Condition100%2/2
$1 || ''
l!l
11
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
189 2 $GBL{'meta'}{'add'}{$class}{'new'} = { 'kind' => 'constructor',
190 'merge_args' => 1,
191 'restricted' => 1 };
192 2 next;
193 }
194  
195 # Private class
196 95 ▶ if ($pkg =~ /^:PRIV(?:ATE)?(?:\((.*)\))?/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg =~ /^:PRIV(?:ATE)?(?:\((.*)\))?/i) 1 94 95
197 1 *{$class.'::new'}
198 = wrap_PRIVATE($class, 'new',
199 2 ▶ sub { goto &Object::InsideOut::new },
Subroutine __ANON__: called CC=1 SCAR=0.0
200 1 ▶ [ $class, grep {$_} split(/[,'\s]+/, $1 || '') ]);
Condition50%1/2
$1 || ''
l!l
10
MC/DC0%0/1
$1 || ''
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
201 1 $GBL{'meta'}{'add'}{$class}{'new'} = { 'kind' => 'constructor',
202 'merge_args' => 1,
203 'private' => 1 };
204 1 next;
205 }
206  
207 # Public class
208 94 ▶ if ($pkg =~ /^:PUB/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg =~ /^:PUB/i) 2 92 94
209 2 ▶ *{$class.'::new'} = sub { goto &Object::InsideOut::new };
Subroutine __ANON__: called CC=1 SCAR=0.0
210 2 $GBL{'meta'}{'add'}{$class}{'new'} = { 'kind' => 'constructor',
211 'merge_args' => 1 };
212 2 next;
213 }
214  
215 # Handle secure flag
216 92 ▶ if ($pkg =~ /^:SECUR/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg =~ /^:SECUR/i) 1 91 92
217 1 $pkg = 'Object::InsideOut::Secure';
218 }
219  
220 # Load the package, if needed
221 92 ▶ if (! $class->isa($pkg)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->isa($pkg)) 92 0 92
222 # If no package symbols, then load it
223 92 ▶ if (! grep { $_ !~ /::$/ } keys(%{$pkg.'::'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {not $_ =~ /::$/;} keys %{$pkg . '::';}) 10 82 92
224 10 eval "require $pkg";
225 10 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 5 5 10
226 5 OIO::Code->die(
227 'message' => "Failure loading package '$pkg'",
228 'Error' => $@);
229 }
230 # Empty packages make no sense
231 5 ▶ if (! grep { $_ !~ /::$/ } keys(%{$pkg.'::'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {not $_ =~ /::$/;} keys %{$pkg . '::';}) 2 3 5
232 2 OIO::Code->die('message' => "Package '$pkg' is empty");
233 }
234 }
235  
236 # Add to package list
237 85 push(@packages, $pkg);
238 }
239  
240  
241 # Import the package, if needed
242 85 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) 0 85 85
243 0 my $imports = shift;
244 0 ▶ if (ref($imports) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $imports ne "ARRAY") 0 0 0
245 0 OIO::Code->die('message' => "Arguments to '$pkg' must be contained within an array reference: $imports");
246 }
247 0 eval { $pkg->import(@{$imports}); };
248 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
249 0 OIO::Code->die(
250 'message' => "Failure running 'import' on package '$pkg'",
251 'Error' => $@);
252 }
253 }
254 }
255  
256 # Create class tree
257 137 my @tree;
258 my %seen; # Used to prevent duplicate entries in @tree
259 137 my $need_oio = 1;
260 137 foreach my $parent (@packages) {
261 85 ▶ if (exists($GBL{'tree'}{'td'}{$parent})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GBL{'tree'}{'td'}{$parent}) { } 79 6 85
262 # Inherit from Object::InsideOut class
263 79 foreach my $ancestor (@{$GBL{'tree'}{'td'}{$parent}}) {
264 129 ▶ if (! exists($seen{$ancestor})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $seen{$ancestor}) 111 18 129
265 111 push(@tree, $ancestor);
266 111 $GBL{'asi'}{$ancestor}{$class} = undef;
267 111 $seen{$ancestor} = undef;
268 }
269 }
270 79 push(@{$class.'::ISA'}, $parent);
271 79 $need_oio = 0;
272  
273 } else { # Inherit from foreign class
274 # Get inheritance 'classes' hash
275 6 ▶ if (! exists($GBL{'heritage'}{$class})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $GBL{"heritage"}{$class}) 6 0 6
276 6 create_heritage($class);
277 }
278 # Add parent to inherited classes
279 6 $GBL{'heritage'}{$class}{'cl'}{$parent} = undef;
280 }
281 }
282  
283 # Add Object::InsideOut to class's @ISA array, if needed
284 137 ▶ if ($need_oio) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_oio) 79 58 137
285 79 push(@{$class.'::ISA'}, 'Object::InsideOut');
286 }
287  
288 # Add calling class to tree
289 137 ▶ if (! exists($seen{$class})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $seen{$class}) 137 0 137
290 137 push(@tree, $class);
291 }
292  
293 # Save the trees
294 137 $GBL{'tree'}{'td'}{$class} = \@tree;
295 137 @{$GBL{'tree'}{'bu'}{$class}} = reverse(@tree);
296  
297 137 $GBL{'init'} = 1; # Need to initialize
298 }
299  
300  
301 ### Attribute Handling ###
302  
303 # Handles subroutine attributes supported by this package.
304 # See 'perldoc attributes' for details.
305 sub MODIFY_CODE_ATTRIBUTES
306 {
307 2074 ▶ my ($pkg, $code, @attrs) = @_;
Subroutine MODIFY_CODE_ATTRIBUTES: called CC=48 SCAR=41.1
308  
309 # Call attribute handlers in the class tree
310 2074 ▶ if (exists($GBL{'attr'}{'MOD'}{'CODE'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GBL{"attr"}{"MOD"}{"CODE"}) 0 2074 2074
311 0 @attrs = CHECK_ATTRS('CODE', $pkg, $code, @attrs);
312 0 ▶ return if (! @attrs);
Branch: 1 branch
BranchTrueFalseTotal
unless @attrs 0 0 0
313 }
314  
315 # Save caller info with code ref for error reporting purposes
316 2074 my %info = (
317 pkg => $pkg,
318 code => $code,
319 wrap => $code,
320 loc => [ $pkg, (caller(2))[1,2] ],
321 );
322  
323 # Special handling for :Restricted :Cumulative/:Chained methods
324 2074 ▶ if ((my ($restrict) = grep(/^RESTRICT(?:ED)?$/i, @attrs)) &&
Branch: 1 branch
BranchTrueFalseTotal
if (my($restrict) = grep(/^RESTRICT(?:ED)?$/i, @attrs) and grep {$_ =~ /^CUM(?:ULATIVE)?$/i or $_ =~ /^CHAIN(?:ED)?$/i;} @attrs) 3 2071 2074
Condition100%3/3
my($restrict) = grep(/^RESTRICT(?:ED)?$/i, @attrs) and grep {$_ =~ /^CUM(?:ULATIVE)?$/i or $_ =~ /^CHAIN(?:ED)?$/i;} @attrs
!ll&&!rl&&r
206563
MC/DC100%2/2
my($restrict) = grep(/^RESTRICT(?:ED)?$/i, @attrs) and grep {$_ =~ /^CUM(?:ULATIVE)?$/i or $_ =~ /^CHAIN(?:ED)?$/i;} @attrs
my($restrict) = grep(/^RESTRICT(?:ED)?$/i, @attrs) grep {$_ =~ /^CUM(?:ULATIVE)?$/i or $_ =~ /^CHAIN(?:ED)?$/i;} @attrs
Truth table100%3/3
A and B
A= my($restrict) = grep(/^RESTRICT(?:ED)?$/i, @attrs)B= grep {$_ =~ /^CUM(?:ULATIVE)?$/i or $_ =~ /^CHAIN(?:ED)?$/i;} @attrs
ABresult
0X0
100
111
325 15 ▶ (grep { ($_ =~ /^CUM(?:ULATIVE)?$/i) ||
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /^CUM(?:ULATIVE)?$/i or $_ =~ /^CHAIN(?:ED)?$/i 12 3 15
326 ($_ =~ /^CHAIN(?:ED)?$/i) } @attrs))
327 {
328 3 @attrs = grep { $_ !~ /^RESTRICT(?:ED)?$/i } @attrs;
329 3 ($info{'exempt'}) = $restrict =~ /^RESTRICT(?:ED)?\((.*)\)/;
330 }
331  
332 2074 my @unused_attrs; # List of any unhandled attributes
333  
334 # Save the code refs in the appropriate hashes
335 2074 ▶ while (my $attribute = shift(@attrs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $attribute = shift @attrs) 3285 2074 5359
336 3285 my ($attr, $arg) = $attribute =~ /(\w+)(?:[(]\s*(.*)\s*[)])?/;
337 3285 $attr = uc($attr);
338  
339 3285 ▶ if ($attr eq 'ID') {
Branch: 21 branches
BranchTrueFalseTotal
if ($attr eq 'ID') { } 4 3281 3285
elsif ($attr eq 'PREINIT') { } 1 3280 3281
elsif ($attr eq 'INIT') { } 16 3264 3280
elsif ($attr =~ /^REPL(?:ICATE)?$/) { } 1 3263 3264
elsif ($attr =~ /^DEST(?:ROY)?$/) { } 2 3261 3263
elsif ($attr =~ /^AUTO(?:METHOD)?$/) { } 4 3257 3261
elsif ($attr =~ /^CUM(?:ULATIVE)?$/) { } 3 3254 3257
elsif ($attr =~ /^CHAIN(?:ED)?$/) { } 27 3227 3254
elsif ($attr =~ /^DUMP(?:ER)?$/) { } 2 3225 3227
elsif ($attr =~ /^PUMP(?:ER)?$/) { } 2 3223 3225
elsif ($attr =~ /^RESTRICT(?:ED)?$/) { } 9 3214 3223
elsif ($attr =~ /^PRIV(?:ATE)?$/) { } 1168 2046 3214
elsif ($attr =~ /^HIDD?EN?$/) { } 36 2010 2046
elsif ($attr =~ /^SUB/) { } 1515 495 2010
elsif ($attr =~ /^METHOD/ and $attribute ne 'method') { } 398 97 495
elsif ($attr =~ /^MERGE/) { } 58 39 97
elsif ($attr =~ /^MOD(?:IFY)?_(ARRAY|CODE|HASH|SCALAR)_ATTR/) { } 3 36 39
elsif ($attr =~ /^FETCH_(ARRAY|CODE|HASH|SCALAR)_ATTR/) { } 1 35 36
elsif ($attr eq 'SCALARIFY') { } 0 35 35
elsif (my($ify) = grep({$_ eq $attr;} 'STRINGIFY', 'NUMERIFY', 'BOOLIFY', 'ARRAYIFY', 'HASHIFY', 'GLOBIFY', 'CODIFY')) { } 35 0 35
elsif (not $attr =~ /^PUB(LIC)?$/) { } 0 0 0
340 4 $GBL{'sub'}{'id'}{$pkg} = \%info;
341 4 ▶ push(@attrs, $arg || 'HIDDEN');
Condition50%1/2
$arg || 'HIDDEN'
l!l
04
MC/DC0%0/1
$arg || 'HIDDEN'
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
342 4 $GBL{'init'} = 1;
343  
344 } elsif ($attr eq 'PREINIT') {
345 1 $GBL{'sub'}{'pre'}{$pkg} = $code;
346 1 ▶ push(@attrs, $arg || 'HIDDEN');
Condition50%1/2
$arg || 'HIDDEN'
l!l
01
MC/DC0%0/1
$arg || 'HIDDEN'
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
347  
348 } elsif ($attr eq 'INIT') {
349 16 $GBL{'sub'}{'init'}{$pkg} = $code;
350 16 ▶ push(@attrs, $arg || 'HIDDEN');
Condition50%1/2
$arg || 'HIDDEN'
l!l
016
MC/DC0%0/1
$arg || 'HIDDEN'
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
351  
352 } elsif ($attr =~ /^REPL(?:ICATE)?$/) {
353 1 $GBL{'sub'}{'repl'}{$pkg} = $code;
354 1 ▶ push(@attrs, $arg || 'HIDDEN');
Condition50%1/2
$arg || 'HIDDEN'
l!l
01
MC/DC0%0/1
$arg || 'HIDDEN'
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
355  
356 } elsif ($attr =~ /^DEST(?:ROY)?$/) {
357 2 $GBL{'sub'}{'dest'}{$pkg} = $code;
358 2 ▶ push(@attrs, $arg || 'HIDDEN');
Condition50%1/2
$arg || 'HIDDEN'
l!l
02
MC/DC0%0/1
$arg || 'HIDDEN'
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
359  
360 } elsif ($attr =~ /^AUTO(?:METHOD)?$/) {
361 4 $GBL{'sub'}{'auto'}{$pkg} = $code;
362 4 ▶ push(@attrs, $arg || 'HIDDEN');
Condition50%1/2
$arg || 'HIDDEN'
l!l
04
MC/DC0%0/1
$arg || 'HIDDEN'
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
363 4 $GBL{'init'} = 1;
364  
365 } elsif ($attr =~ /^CUM(?:ULATIVE)?$/) {
366 3 ▶ push(@{$GBL{'sub'}{'cumu'}{'new'}{($arg && $arg =~ /BOTTOM/i) ? 'bu' : 'td'}}, \%info);
Branch: 1 branch
BranchTrueFalseTotal
$arg && $arg =~ /BOTTOM/i ? : 0 3 3
Condition33%1/3
$arg and $arg =~ /BOTTOM/i
!ll&&!rl&&r
300
MC/DC0%0/2
$arg and $arg =~ /BOTTOM/i
$arg $arg =~ /BOTTOM/i
Truth table33%1/3
A and B
A= $argB= $arg =~ /BOTTOM/i
ABresult
0X0
100
111
367 3 $GBL{'init'} = 1;
368  
369 } elsif ($attr =~ /^CHAIN(?:ED)?$/) {
370 27 ▶ push(@{$GBL{'sub'}{'chain'}{'new'}{($arg && $arg =~ /BOTTOM/i) ? 'bu' : 'td'}}, \%info);
Branch: 1 branch
BranchTrueFalseTotal
$arg && $arg =~ /BOTTOM/i ? : 9 18 27
Condition66%2/3
$arg and $arg =~ /BOTTOM/i
!ll&&!rl&&r
1809
MC/DC50%1/2
$arg and $arg =~ /BOTTOM/i
$arg $arg =~ /BOTTOM/i
Truth table66%2/3
A and B
A= $argB= $arg =~ /BOTTOM/i
ABresult
0X0
100
111
371 27 $GBL{'init'} = 1;
372  
373 } elsif ($attr =~ /^DUMP(?:ER)?$/) {
374 2 $GBL{'dump'}{'dumper'}{$pkg} = $code;
375 2 ▶ push(@attrs, $arg || 'HIDDEN');
Condition50%1/2
$arg || 'HIDDEN'
l!l
02
MC/DC0%0/1
$arg || 'HIDDEN'
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
376  
377 } elsif ($attr =~ /^PUMP(?:ER)?$/) {
378 2 $GBL{'dump'}{'pumper'}{$pkg} = $code;
379 2 ▶ push(@attrs, $arg || 'HIDDEN');
Condition50%1/2
$arg || 'HIDDEN'
l!l
02
MC/DC0%0/1
$arg || 'HIDDEN'
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
380  
381 } elsif ($attr =~ /^RESTRICT(?:ED)?$/) {
382 9 $info{'exempt'} = $arg;
383 9 push(@{$GBL{'perm'}{'restr'}}, \%info);
384 9 $GBL{'init'} = 1;
385  
386 } elsif ($attr =~ /^PRIV(?:ATE)?$/) {
387 1168 $info{'exempt'} = $arg;
388 1168 push(@{$GBL{'perm'}{'priv'}}, \%info);
389 1168 $GBL{'init'} = 1;
390  
391 } elsif ($attr =~ /^HIDD?EN?$/) {
392 36 push(@{$GBL{'perm'}{'hide'}}, \%info);
393 36 $GBL{'init'} = 1;
394  
395 } elsif ($attr =~ /^SUB/) {
396 1515 push(@{$GBL{'meta'}{'subr'}}, \%info);
397 1515 ▶ if ($arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) 1157 358 1515
398 1157 push(@attrs, $arg);
399 }
400 1515 $GBL{'init'} = 1;
401  
402 ▶ } elsif ($attr =~ /^METHOD/ && $attribute ne 'method') {
Condition66%2/3
$attr =~ /^METHOD/ and $attribute ne "method"
!ll&&!rl&&r
970398
MC/DC50%1/2
$attr =~ /^METHOD/ and $attribute ne "method"
$attr =~ /^METHOD/ $attribute ne "method"
Truth table66%2/3
A and B
A= $attr =~ /^METHOD/B= $attribute ne "method"
ABresult
0X0
100
111
403 398 ▶ if ($arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) 396 2 398
404 396 $info{'kind'} = lc($arg);
405 396 push(@{$GBL{'meta'}{'method'}}, \%info);
406 396 $GBL{'init'} = 1;
407 }
408  
409 } elsif ($attr =~ /^MERGE/) {
410 58 push(@{$GBL{'merge'}}, \%info);
411 58 ▶ if ($arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) 0 58 58
412 0 push(@attrs, $arg);
413 }
414 58 $GBL{'init'} = 1;
415  
416 } elsif ($attr =~ /^MOD(?:IFY)?_(ARRAY|CODE|HASH|SCALAR)_ATTR/) {
417 3 install_ATTRIBUTES(\%GBL);
418 3 $GBL{'attr'}{'MOD'}{$1}{$pkg} = $code;
419 3 ▶ push(@attrs, $arg || 'HIDDEN');
Condition50%1/2
$arg || 'HIDDEN'
l!l
03
MC/DC0%0/1
$arg || 'HIDDEN'
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
420  
421 } elsif ($attr =~ /^FETCH_(ARRAY|CODE|HASH|SCALAR)_ATTR/) {
422 1 install_ATTRIBUTES(\%GBL);
423 1 push(@{$GBL{'attr'}{'FETCH'}{$1}}, $code);
424 1 ▶ push(@attrs, $arg || 'HIDDEN');
Condition50%1/2
$arg || 'HIDDEN'
l!l
01
MC/DC0%0/1
$arg || 'HIDDEN'
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
425  
426 } elsif ($attr eq 'SCALARIFY') {
427 0 OIO::Attribute->die(
428 'message' => q/:SCALARIFY not allowed/,
429 'Info' => q/The scalar of an object is its object ID, and can't be redefined/,
430 'ignore_package' => 'attributes');
431  
432 245 } elsif (my ($ify) = grep { $_ eq $attr } (qw(STRINGIFY
433 NUMERIFY
434 BOOLIFY
435 ARRAYIFY
436 HASHIFY
437 GLOBIFY
438 CODIFY)))
439 {
440 # Overload (-ify) attributes
441 35 $info{'ify'} = $ify;
442 35 push(@{$GBL{'sub'}{'ol'}}, \%info);
443 35 $GBL{'init'} = 1;
444  
445 } elsif ($attr !~ /^PUB(LIC)?$/) { # PUBLIC is ignored
446 # Not handled
447 0 push(@unused_attrs, $attribute);
448 }
449 }
450  
451 # If using Attribute::Handlers, send it any unused attributes
452 2074 ▶ if (@unused_attrs &&
Branch: 1 branch
BranchTrueFalseTotal
if (@unused_attrs and "Attribute::Handlers::UNIVERSAL"->can("MODIFY_CODE_ATTRIBUTES")) 0 2074 2074
Condition33%1/3
@unused_attrs and "Attribute::Handlers::UNIVERSAL"->can("MODIFY_CODE_ATTRIBUTES")
!ll&&!rl&&r
207400
MC/DC0%0/2
@unused_attrs and "Attribute::Handlers::UNIVERSAL"->can("MODIFY_CODE_ATTRIBUTES")
@unused_attrs "Attribute::Handlers::UNIVERSAL"->can("MODIFY_CODE_ATTRIBUTES")
Truth table33%1/3
A and B
A= @unused_attrsB= "Attribute::Handlers::UNIVERSAL"->can("MODIFY_CODE_ATTRIBUTES")
ABresult
0X0
100
111
453 Attribute::Handlers::UNIVERSAL->can('MODIFY_CODE_ATTRIBUTES'))
454 {
455 0 return (Attribute::Handlers::UNIVERSAL::MODIFY_CODE_ATTRIBUTES($pkg, $code, @unused_attrs));
456 }
457  
458 # Return any unused attributes
459 2074 return (@unused_attrs);
460 }
461  
462 44 my $BALANCED_PARENS; # Must declare before assigning (so var in scope for regex)
463 44 $BALANCED_PARENS = qr{(?>(?:(?>[^()]+)|[(](??{$BALANCED_PARENS})[)])*)};
464  
465 # Handles hash field and :InitArgs attributes.
466 sub MODIFY_HASH_ATTRIBUTES :Sub
467 {
468 56 ▶ my ($pkg, $hash, @attrs) = @_;
Subroutine MODIFY_HASH_ATTRIBUTES: called CC=17 SCAR=38.0
469  
470 # Call attribute handlers in the class tree
471 56 ▶ if (exists($GBL{'attr'}{'MOD'}{'HASH'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GBL{"attr"}{"MOD"}{"HASH"}) 0 56 56
472 0 @attrs = CHECK_ATTRS('HASH', $pkg, $hash, @attrs);
473 0 ▶ return if (! @attrs);
Branch: 1 branch
BranchTrueFalseTotal
unless @attrs 0 0 0
474 }
475  
476 56 my @unused_attrs; # List of any unhandled attributes
477  
478 # Process attributes
479 56 foreach my $attr (@attrs) {
480 # Declaration for object field hash
481 67 ▶ if ($attr =~ /^(?:Field|[GS]et|Acc|Com|Mut|St(?:an)?d|LV(alue)?|All|R(?:ead)?O(?:nly)?|Arg|Type|Hand)/i) {
Branch: 8 branches
BranchTrueFalseTotal
if ($attr =~ /^(?:Field|[GS]et|Acc|Com|Mut|St(?:an)?d|LV(alue)?|All|R(?:ead)?O(?:nly)?|Arg|Type|Hand)/i) { } 36 31 67
elsif ($attr =~ /^Weak$/i) { } 0 31 31
elsif ($attr =~ /^Deep$/i) { } 0 31 31
elsif ($attr =~ /^Def(?:ault)?[(]($BALANCED_PARENS)[)]$/i) { } 2 29 31
elsif ($attr =~ /^Seq(?:uence)?(?:From)?[(]($BALANCED_PARENS)[)]$/i) { } 0 29 29
elsif ($attr =~ /^Name\s*[(]\s*'?([^)'\s]+)'?\s*[)]/i) { } 1 28 29
elsif ($attr =~ /^InitArgs?$/i) { } 28 0 28
elsif ($attr ne 'shared') { } 0 0 0
482 # Save hash ref and attribute
483 # Accessors will be built during initialization
484 36 ▶ if ($attr =~ /^(?:Field|Type)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ /^(?:Field|Type)/i) { } 28 8 36
485 28 unshift(@{$GBL{'fld'}{'new'}{$pkg}}, [ $hash, $attr ]);
486 } else {
487 8 push(@{$GBL{'fld'}{'new'}{$pkg}}, [ $hash, $attr ]);
488 }
489 36 $GBL{'init'} = 1; # Flag that initialization is required
490 }
491  
492 # Weak field
493 elsif ($attr =~ /^Weak$/i) {
494 0 $GBL{'fld'}{'weak'}{$hash} = 1;
495 0 push(@{$GBL{'fld'}{'regen'}{'weak'}}, $hash);
496 }
497  
498 # Deep cloning field
499 elsif ($attr =~ /^Deep$/i) {
500 0 $GBL{'fld'}{'deep'}{$hash} = 1;
501 0 push(@{$GBL{'fld'}{'regen'}{'deep'}}, $hash);
502 }
503  
504 # Defaults
505 elsif ($attr =~ /^Def(?:ault)?[(]($BALANCED_PARENS)[)]$/i) {
506 2 my $val;
507 2 eval "package $pkg; use $]; \$val = sub { my \$self = \$_[0]; $1 }";
508 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
509 0 OIO::Attribute->die(
510 'location' => [ $pkg, (caller(2))[1,2] ],
511 'message' => "Bad ':Default' attribute in package '$pkg'",
512 'Attribute' => $attr,
513 'Error' => $@);
514 }
515 2 push(@{$GBL{'fld'}{'def'}{$pkg}}, [ $hash, $val ]);
516 }
517  
518 # Sequentials
519 elsif ($attr =~ /^Seq(?:uence)?(?:From)?[(]($BALANCED_PARENS)[)]$/i) {
520 0 my $val = $1;
521 0 eval qq{
522 package $pkg;
523 my \$next = $val;
524 \$val = eval{ \$next->can('next') }
525 ? sub { \$next->next() }
526 : sub { \$next++ };
527 };
528 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
529 0 OIO::Attribute->die(
530 'location' => [ $pkg, (caller(2))[1,2] ],
531 'message' => "Bad ':SequenceFrom' attribute in package '$pkg'",
532 'Attribute' => $attr,
533 'Error' => $@);
534 }
535 0 push(@{$GBL{'fld'}{'def'}{$pkg}}, [ $hash, $val ]);
536 }
537  
538 # Field name for dump
539 elsif ($attr =~ /^Name\s*[(]\s*'?([^)'\s]+)'?\s*[)]/i) {
540 1 $GBL{'dump'}{'fld'}{$pkg}{$1} = { fld => $hash, src => 'Name' };
541 }
542  
543 # Declaration for object initializer hash
544 elsif ($attr =~ /^InitArgs?$/i) {
545 28 $GBL{'args'}{$pkg} = $hash;
546 28 push(@{$GBL{'dump'}{'args'}}, $pkg);
547 }
548  
549 # Unhandled
550 # (Must filter out ':shared' attribute due to Perl bug)
551 elsif ($attr ne 'shared') {
552 0 push(@unused_attrs, $attr);
553 }
554 }
555  
556 # If using Attribute::Handlers, send it any unused attributes
557 56 ▶ if (@unused_attrs &&
Branch: 1 branch
BranchTrueFalseTotal
if (@unused_attrs and "Attribute::Handlers::UNIVERSAL"->can("MODIFY_HASH_ATTRIBUTES")) 0 56 56
Condition33%1/3
@unused_attrs and "Attribute::Handlers::UNIVERSAL"->can("MODIFY_HASH_ATTRIBUTES")
!ll&&!rl&&r
5600
MC/DC0%0/2
@unused_attrs and "Attribute::Handlers::UNIVERSAL"->can("MODIFY_HASH_ATTRIBUTES")
@unused_attrs "Attribute::Handlers::UNIVERSAL"->can("MODIFY_HASH_ATTRIBUTES")
Truth table33%1/3
A and B
A= @unused_attrsB= "Attribute::Handlers::UNIVERSAL"->can("MODIFY_HASH_ATTRIBUTES")
ABresult
0X0
100
111
558 Attribute::Handlers::UNIVERSAL->can('MODIFY_HASH_ATTRIBUTES'))
559 {
560 0 return (Attribute::Handlers::UNIVERSAL::MODIFY_HASH_ATTRIBUTES($pkg, $hash, @unused_attrs));
561 }
562  
563 # Return any unused attributes
564 56 return (@unused_attrs);
565 45 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
566  
567  
568 # Handles array field attributes.
569 sub MODIFY_ARRAY_ATTRIBUTES :Sub
570 {
571 137 ▶ my ($pkg, $array, @attrs) = @_;
Subroutine MODIFY_ARRAY_ATTRIBUTES: called CC=16 SCAR=28.9
572  
573 # Call attribute handlers in the class tree
574 137 ▶ if (exists($GBL{'attr'}{'MOD'}{'ARRAY'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GBL{"attr"}{"MOD"}{"ARRAY"}) 2 135 137
575 2 @attrs = CHECK_ATTRS('ARRAY', $pkg, $array, @attrs);
576 2 ▶ return if (! @attrs);
Branch: 1 branch
BranchTrueFalseTotal
unless @attrs 0 2 2
577 }
578  
579 137 my @unused_attrs; # List of any unhandled attributes
580  
581 # Process attributes
582 137 foreach my $attr (@attrs) {
583 # Declaration for object field array
584 263 ▶ if ($attr =~ /^(?:Field|[GS]et|Acc|Com|Mut|St(?:an)?d|LV(alue)?|All|R(?:ead)?O(?:nly)?|Arg|Type|Hand)/i) {
Branch: 7 branches
BranchTrueFalseTotal
if ($attr =~ /^(?:Field|[GS]et|Acc|Com|Mut|St(?:an)?d|LV(alue)?|All|R(?:ead)?O(?:nly)?|Arg|Type|Hand)/i) { } 237 26 263
elsif ($attr =~ /^Weak$/i) { } 1 25 26
elsif ($attr =~ /^Deep$/i) { } 1 24 25
elsif ($attr =~ /^Def(?:ault)?[(]($BALANCED_PARENS)[)]$/i) { } 17 7 24
elsif ($attr =~ /^Seq(?:uence)?(?:From)?[(]($BALANCED_PARENS)[)]$/i) { } 3 4 7
elsif ($attr =~ /^Name\s*[(]\s*'?([^)'\s]+)'?\s*[)]/i) { } 4 0 4
elsif ($attr ne 'shared') { } 0 0 0
585 # Save array ref and attribute
586 # Accessors will be built during initialization
587 237 ▶ if ($attr =~ /^(?:Field|Type)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ /^(?:Field|Type)/i) { } 156 81 237
588 156 unshift(@{$GBL{'fld'}{'new'}{$pkg}}, [ $array, $attr ]);
589 } else {
590 81 push(@{$GBL{'fld'}{'new'}{$pkg}}, [ $array, $attr ]);
591 }
592 237 $GBL{'init'} = 1; # Flag that initialization is required
593 }
594  
595 # Weak field
596 elsif ($attr =~ /^Weak$/i) {
597 1 $GBL{'fld'}{'weak'}{$array} = 1;
598 1 push(@{$GBL{'fld'}{'regen'}{'weak'}}, $array);
599 }
600  
601 # Deep cloning field
602 elsif ($attr =~ /^Deep$/i) {
603 1 $GBL{'fld'}{'deep'}{$array} = 1;
604 1 push(@{$GBL{'fld'}{'regen'}{'deep'}}, $array);
605 }
606  
607 # Defaults
608 elsif ($attr =~ /^Def(?:ault)?[(]($BALANCED_PARENS)[)]$/i) {
609 17 my $val;
610 17 eval "package $pkg; use $]; \$val = sub { my \$self = \$_[0]; $1 }";
611 17 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 17 17
612 0 OIO::Attribute->die(
613 'location' => [ $pkg, (caller(2))[1,2] ],
614 'message' => "Bad ':Default' attribute in package '$pkg'",
615 'Attribute' => $attr,
616 'Error' => $@);
617 }
618 17 push(@{$GBL{'fld'}{'def'}{$pkg}}, [ $array, $val ]);
619 }
620  
621 # Sequentials
622 elsif ($attr =~ /^Seq(?:uence)?(?:From)?[(]($BALANCED_PARENS)[)]$/i) {
623 3 my $val = $1;
624 3 eval qq{
625 package $pkg;
626 my \$next = $val;
627 \$val = eval{ \$next->can('next') }
628 ? sub { \$next->next() }
629 : sub { \$next++ };
630 };
631 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 3 3
632 0 OIO::Attribute->die(
633 'location' => [ $pkg, (caller(2))[1,2] ],
634 'message' => "Bad ':SequenceFrom' attribute in package '$pkg'",
635 'Attribute' => $attr,
636 'Error' => $@);
637 }
638 3 push(@{$GBL{'fld'}{'def'}{$pkg}}, [ $array, $val ]);
639 }
640  
641 # Field name for dump
642 elsif ($attr =~ /^Name\s*[(]\s*'?([^)'\s]+)'?\s*[)]/i) {
643 4 $GBL{'dump'}{'fld'}{$pkg}{$1} = { fld => $array, src => 'Name' };
644 }
645  
646 # Unhandled
647 # (Must filter out ':shared' attribute due to Perl bug)
648 elsif ($attr ne 'shared') {
649 0 push(@unused_attrs, $attr);
650 }
651 }
652  
653 # If using Attribute::Handlers, send it any unused attributes
654 137 ▶ if (@unused_attrs &&
Branch: 1 branch
BranchTrueFalseTotal
if (@unused_attrs and "Attribute::Handlers::UNIVERSAL"->can("MODIFY_ARRAY_ATTRIBUTES")) 0 137 137
Condition33%1/3
@unused_attrs and "Attribute::Handlers::UNIVERSAL"->can("MODIFY_ARRAY_ATTRIBUTES")
!ll&&!rl&&r
13700
MC/DC0%0/2
@unused_attrs and "Attribute::Handlers::UNIVERSAL"->can("MODIFY_ARRAY_ATTRIBUTES")
@unused_attrs "Attribute::Handlers::UNIVERSAL"->can("MODIFY_ARRAY_ATTRIBUTES")
Truth table33%1/3
A and B
A= @unused_attrsB= "Attribute::Handlers::UNIVERSAL"->can("MODIFY_ARRAY_ATTRIBUTES")
ABresult
0X0
100
111
655 Attribute::Handlers::UNIVERSAL->can('MODIFY_ARRAY_ATTRIBUTES'))
656 {
657 0 return (Attribute::Handlers::UNIVERSAL::MODIFY_ARRAY_ATTRIBUTES($pkg, $array, @unused_attrs));
658 }
659  
660 # Return any unused attributes
661 137 return (@unused_attrs);
662 45 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
663  
664  
665 ### Array-based Object Support ###
666  
667 # Supplies an ID for an object being created in a class tree
668 # and reclaims IDs from destroyed objects
669 sub _ID :Sub
670 {
671 341 ▶ return if $GBL{'term'}; # Ignore during global cleanup
Subroutine _ID: called CC=18 SCAR=30.5
Branch: 1 branch
BranchTrueFalseTotal
if $GBL{"term"} 0 341 341
672  
673 341 my ($class, $id) = @_; # The object's class and id
674 341 my $tree = $GBL{'sub'}{'id'}{$class}{'pkg'};
675  
676  
677 # If class is sharing, then all ID tracking is done as though in thread 0,
678 # else tracking is done per thread
679 341 my $sharing = is_sharing($class);
680 341 ▶ my $thread_id = ($sharing) ? 0 : $GBL{'tid'};
Branch: 1 branch
BranchTrueFalseTotal
$sharing ? : 0 341 341
681  
682 # Save deleted IDs for later reuse
683 341 my $reuse = $GBL{'id'}{'reuse'};
684 341 ▶ if ($id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 169 172 341
685 169 ▶ if (! exists($$reuse{$tree})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $reuse->{$tree}) 61 108 169
686 61 ▶ $$reuse{$tree} = ($sharing) ? make_shared([]) : [];
Branch: 1 branch
BranchTrueFalseTotal
$sharing ? : 0 61 61
687 }
688 169 ▶ lock($$reuse{$tree}) if $sharing;
Branch: 1 branch
BranchTrueFalseTotal
if $sharing 0 169 169
689 169 my $r_tree = $$reuse{$tree};
690 169 ▶ if (! defined($$r_tree[$thread_id])) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $r_tree->[$thread_id]) { } 61 108 169
691 61 ▶ $$r_tree[$thread_id] = ($sharing) ? make_shared([]) : [];
Branch: 1 branch
BranchTrueFalseTotal
$sharing ? : 0 61 61
692 } else {
693 108 foreach (@{$$r_tree[$thread_id]}) {
694 68 ▶ if ($_ == $id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ == $id) 0 68 68
695 0 warn("ERROR: Duplicate reclaimed object ID ($id) in class tree for $tree in thread $thread_id\n");
696 0 return;
697 }
698 }
699 }
700 169 push(@{$$r_tree[$thread_id]}, $id);
701 169 return;
702 }
703  
704 # Use a reclaimed ID if available
705 172 ▶ if (exists($$reuse{$tree})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $reuse->{$tree}) 65 107 172
706 65 ▶ lock($$reuse{$tree}) if $sharing;
Branch: 1 branch
BranchTrueFalseTotal
if $sharing 0 65 65
707 65 ▶ if (defined($$reuse{$tree}[$thread_id])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $reuse->{$tree}[$thread_id]) 65 0 65
708 65 my $id = pop(@{$$reuse{$tree}[$thread_id]});
709 65 ▶ if (defined($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 64 1 65
710 64 return $id;
711 }
712 }
713 }
714  
715 # Return the next ID
716 108 my $g_id = $GBL{'id'}{'obj'};
717 108 ▶ if (exists($$g_id{$tree})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $g_id->{$tree}) 46 62 108
718 46 ▶ lock($$g_id{$tree}) if $sharing;
Branch: 1 branch
BranchTrueFalseTotal
if $sharing 0 46 46
719 46 return (++$$g_id{$tree}[$thread_id]);
720 }
721 62 ▶ if ($sharing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sharing) 0 62 62
722 0 $$g_id{$tree} = make_shared([]);
723 0 lock($$g_id{$tree});
724 0 return (++$$g_id{$tree}[$thread_id]);
725 }
726 62 $$g_id{$tree} = [];
727 62 return (++$$g_id{$tree}[$thread_id]);
728 45 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
729  
730  
731 ### Initialization Handling ###
732  
733 # Finds a subroutine's name from its code ref
734 sub sub_name :Sub(Private)
735 {
736 2072 ▶ my ($ref, $attr, $location) = @_;
Subroutine sub_name: called CC=3 SCAR=12.0
Pod undocumented
737  
738 2072 my $name;
739 2072 eval { $name = B::svref_2object($ref)->GV()->NAME(); };
740 2072 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 2072 2072
elsif ($name eq '__ANON__') { } 0 2072 2072
741 0 OIO::Attribute->die(
742 'location' => $location,
743 'message' => "Failure finding name for subroutine with $attr attribute",
744 'Error' => $@);
745  
746 } elsif ($name eq '__ANON__') {
747 0 OIO::Attribute->die(
748 'location' => $location,
749 'message' => q/Subroutine name not found/,
750 'Info' => "Can't use anonymous subroutine for $attr attribute");
751 }
752  
753 2072 return ($name); # Found
754 45 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
755  
756  
757 # Perform much of the 'magic' for this module
758 sub initialize :Sub(Private)
759 {
760 256 ▶ return if (! delete($GBL{'init'}));
Subroutine initialize: called CC=83 SCAR=55.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless delete $GBL{"init"} 120 136 256
761  
762 136 my $trees = $GBL{'tree'}{'td'};
763 136 my $id_subs = $GBL{'sub'}{'id'};
764 136 my $obj_ids = $GBL{'id'}{'obj'};
765  
766 45 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
767 45 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
768  
769 # Determine classes that need ID subs
770 # Purge existing references to the default ID sub (i.e., _ID)
771 # if no objects exist in that hierarchy
772 136 my %need_id_sub;
773 136 foreach my $class (keys(%{$trees})) {
774 280 ▶ if (! exists($$id_subs{$class})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $id_subs->{$class}) { } 134 146 280
elsif ($id_subs->{$class}{'code'} == \&Object::InsideOut::_ID and not exists $$obj_ids{$id_subs->{$class}{'pkg'}}) { } 113 47 160
775 134 $need_id_sub{$class} = undef;
776 ▶ } elsif (($$id_subs{$class}{'code'} == \&_ID) &&
Condition100%3/3
$id_subs->{$class}{"code"} == \&Object::InsideOut::_ID and not exists $$obj_ids{$id_subs->{$class}{"pkg"}}
!ll&&!rl&&r
1419113
MC/DC100%2/2
$id_subs->{$class}{"code"} == \&Object::InsideOut::_ID and not exists $$obj_ids{$id_subs->{$class}{"pkg"}}
$id_subs->{$class}{"code"} == \&Object::InsideOut::_ID not exists $$obj_ids{$id_subs->{$class}{"pkg"}}
Truth table100%3/3
A and not(B)
A= $id_subs->{$class}{"code"} == \&Object::InsideOut::_IDB= not exists $$obj_ids{$id_subs->{$class}{"pkg"}}
ABresult
0X0
100
111
777 ! exists($$obj_ids{$$id_subs{$class}{'pkg'}}))
778 {
779 113 delete($$id_subs{$class});
780 113 $need_id_sub{$class} = undef;
781 }
782 }
783  
784 # Get ID subs to propagate
785 136 my %to_propagate;
786 136 foreach my $class (keys(%{$id_subs})) {
787 33 $to_propagate{$$id_subs{$class}{'pkg'}} = undef;
788 }
789  
790 # Propagate ID subs to classes
791 136 ▶ while (%need_id_sub) {
Branch: 1 branch
BranchTrueFalseTotal
if (%need_id_sub) 147 136 283
792 # Get ID sub package
793 147 my $pkg;
794 147 ▶ if (%to_propagate) {
Branch: 1 branch
BranchTrueFalseTotal
if (%to_propagate) { } 12 135 147
795 12 ($pkg) = keys(%to_propagate);
796 12 delete($to_propagate{$pkg});
797 } else {
798 135 (my $class) = keys(%need_id_sub);
799 135 $pkg = $$trees{$class}[0];
800 135 delete($need_id_sub{$pkg});
801 135 ▶ if (! defined($pkg)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pkg) 0 135 135
802 # bug
803 0 OIO::Internal->die(
804 'message' => "Class '$class' has empty tree",
805 );
806 }
807 135 ▶ if (exists($$id_subs{$pkg})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $id_subs->{$pkg}) 0 135 135
808 # bug
809 0 OIO::Internal->die(
810 'message' => "ID sub for '$pkg' exists but was not propagated properly",
811 );
812 }
813 135 $$id_subs{$pkg} = {
814 pkg => $pkg,
815 code => \&_ID,
816 loc => [ '', 'Default :ID sub', 0 ],
817 };
818 }
819  
820 # Add ID sub to classes using package
821 147 ▶ next if (! exists($GBL{'asi'}{$pkg}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $GBL{"asi"}{$pkg} 94 53 147
822 53 my @propagate_to = keys(%{$GBL{'asi'}{$pkg}});
823 53 my %seen = map { $_ => undef } @propagate_to;
824 53 ▶ while (my $class = pop(@propagate_to)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = pop @propagate_to) 505 53 558
825 505 ▶ if (exists($$id_subs{$class})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $id_subs->{$class}) { } 393 112 505
826 # Verify it's the same ID sub
827 393 ▶ if (($$id_subs{$class}{'code'} != $$id_subs{$pkg}{'code'}) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($id_subs->{$class}{"code"} != $id_subs->{$pkg}{"code"} or $id_subs->{$class}{"pkg"} ne $id_subs->{$pkg}{"pkg"}) 0 393 393
Condition33%1/3
$id_subs->{$class}{"code"} != $id_subs->{$pkg}{"code"} or $id_subs->{$class}{"pkg"} ne $id_subs->{$pkg}{"pkg"}
l!l&&r!l&&!r
00393
MC/DC0%0/2
$id_subs->{$class}{"code"} != $id_subs->{$pkg}{"code"} or $id_subs->{$class}{"pkg"} ne $id_subs->{$pkg}{"pkg"}
$id_subs->{$class}{"code"} != $id_subs->{$pkg}{"code"} $id_subs->{$class}{"pkg"} ne $id_subs->{$pkg}{"pkg"}
Truth table33%1/3
A or B
A= $id_subs->{$class}{"code"} != $id_subs->{$pkg}{"code"}B= $id_subs->{$class}{"pkg"} ne $id_subs->{$pkg}{"pkg"}
ABresult
1X1
011
000
828 ($$id_subs{$class}{'pkg'} ne $$id_subs{$pkg}{'pkg'}))
829 {
830 # Runtime merging of hierarchies with existing objects
831 0 ▶ if (($$id_subs{$class}{'code'} == \&_ID) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($id_subs->{$class}{"code"} == \&Object::InsideOut::_ID or $id_subs->{$pkg}{"code"} == \&Object::InsideOut::_ID) 0 0 0
Condition0%0/3
$id_subs->{$class}{"code"} == \&Object::InsideOut::_ID or $id_subs->{$pkg}{"code"} == \&Object::InsideOut::_ID
l!l&&r!l&&!r
000
MC/DC0%0/2
$id_subs->{$class}{"code"} == \&Object::InsideOut::_ID or $id_subs->{$pkg}{"code"} == \&Object::InsideOut::_ID
$id_subs->{$class}{"code"} == \&Object::InsideOut::_ID $id_subs->{$pkg}{"code"} == \&Object::InsideOut::_ID
Truth table0%0/3
A or B
A= $id_subs->{$class}{"code"} == \&Object::InsideOut::_IDB= $id_subs->{$pkg}{"code"} == \&Object::InsideOut::_ID
ABresult
1X1
011
000
832 ($$id_subs{$pkg}{'code'} == \&_ID))
833 {
834 OIO::Runtime->die(
835 'message' => "Possible extant objects prevent runtime creation of hierarchy for class '$class'",
836 'Info' => "Runtime loading of classes needs to be performed before any objects are created within their hierarchies",
837 ((($$id_subs{$class}{'code'} == \&_ID) && ($$id_subs{$pkg}{'code'} == \&_ID))
838 ? ()
839 : ('Class1' => "The hierarchy for '$$id_subs{$class}{'pkg'}' is using object IDs generated by " .
840 (($$id_subs{$class}{'code'} == \&_ID) ? 'Object::InsideOut' : 'a custom :ID subroutine'),
841 'Class2' => "The hierarchy for '$$id_subs{$pkg}{'pkg'}' is using object IDs generated by " .
842 0 ▶ (($$id_subs{$pkg}{'code'} == \&_ID) ? 'Object::InsideOut' : 'a custom :ID subroutine'))));
Branch: 3 branches
BranchTrueFalseTotal
$id_subs->{$class}{'code'} == \&Object::InsideOut::_ID && $id_subs->{$pkg}{'code'} == \&Object::InsideOut::_ID ? : 0 0 0
$id_subs->{$class}{'code'} == \&Object::InsideOut::_ID ? : 0 0 0
$id_subs->{$pkg}{'code'} == \&Object::InsideOut::_ID ? : 0 0 0
Condition0%0/3
$id_subs->{$class}{"code"} == \&Object::InsideOut::_ID and $id_subs->{$pkg}{"code"} == \&Object::InsideOut::_ID
!ll&&!rl&&r
000
MC/DC0%0/2
$id_subs->{$class}{"code"} == \&Object::InsideOut::_ID and $id_subs->{$pkg}{"code"} == \&Object::InsideOut::_ID
$id_subs->{$class}{"code"} == \&Object::InsideOut::_ID $id_subs->{$pkg}{"code"} == \&Object::InsideOut::_ID
Truth table0%0/3
A and B
A= $id_subs->{$class}{"code"} == \&Object::InsideOut::_IDB= $id_subs->{$pkg}{"code"} == \&Object::InsideOut::_ID
ABresult
0X0
100
111
843 }
844 # Multiple :ID subs in hierarchy
845 0 my (undef, $file, $line) = @{$$id_subs{$class}{'loc'}};
846 0 my (undef, $file2, $line2) = @{$$id_subs{$pkg}{'loc'}};
847 0 OIO::Attribute->die(
848 'message' => "Multiple :ID subs defined within hierarchy for class '$class'",
849 'Info' => ":ID subs in class '$$id_subs{$class}{'pkg'}' (file '$file', line $line), and class '$$id_subs{$pkg}{'pkg'}' (file '$file2', line $line2)");
850 }
851 } else {
852 # Add ID sub to class
853 112 $$id_subs{$class} = $$id_subs{$pkg};
854 112 delete($need_id_sub{$class});
855 # Propagate to classes in this class's tree
856 112 foreach my $add (@{$$trees{$class}}) {
857 306 ▶ if (! defined($seen{$add})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $seen{$add}) 306 0 306
858 306 push(@propagate_to, $add);
859 306 $seen{$add} = undef;
860 }
861 }
862 # Propagate to classes that use this one
863 112 ▶ if (exists($GBL{'asi'}{$class})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GBL{"asi"}{$class}) 55 57 112
864 55 foreach my $add (keys(%{$GBL{'asi'}{$class}})) {
865 96 ▶ if (! defined($seen{$add})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $seen{$add}) 96 0 96
866 96 push(@propagate_to, $add);
867 96 $seen{$add} = undef;
868 }
869 }
870 }
871 }
872 }
873 }
874  
875 136 ▶ if ($GBL{'share'}{'ok'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($GBL{"share"}{"ok"}) 0 136 136
876 # If needed, process any thread object sharing flags
877 0 my $sh_cl = $GBL{'share'}{'cl'};
878 0 foreach my $flag_class (keys(%{$sh_cl})) {
879 # Find the class in any class tree
880 0 foreach my $tree (values(%{$trees})) {
881 0 ▶ if (grep(/^$flag_class$/, @$tree)) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^$flag_class$/, @$tree) 0 0 0
882 # Check each class in the tree
883 0 foreach my $class (@$tree) {
884 0 ▶ if (exists($$sh_cl{$class})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $sh_cl->{$class}) { } 0 0 0
885 # Check for sharing conflicts
886 0 ▶ if ($$sh_cl{$class}{'share'}
Branch: 1 branch
BranchTrueFalseTotal
if ($sh_cl->{$class}{"share"} != $sh_cl->{$flag_class}{"share"}) 0 0 0
887 != $$sh_cl{$flag_class}{'share'})
888 {
889 my ($pkg1, $pkg2)
890 0 ▶ = ($$sh_cl{$flag_class}{'share'})
Branch: 1 branch
BranchTrueFalseTotal
$sh_cl->{$flag_class}{'share'} ? : 0 0 0
891 ? ($flag_class, $class)
892 : ($class, $flag_class);
893 my @loc = ($pkg1,
894 $$sh_cl{$pkg1}{'file'},
895 0 $$sh_cl{$pkg1}{'line'});
896 0 OIO::Code->die(
897 'location' => \@loc,
898 'message' => "Can't combine thread-sharing classes ($pkg1) with non-sharing classes ($pkg2) in the same class tree",
899 'Info' => "Class '$pkg1' was declared as sharing (file '$loc[1]' line $loc[2]), but class '$pkg2' was declared as non-sharing (file '$$sh_cl{$pkg2}{'file'}' line $$sh_cl{$pkg2}{'line'})");
900 }
901 } else {
902 # Add the sharing flag to this class
903 0 $$sh_cl{$class} = $$sh_cl{$flag_class};
904 }
905 }
906 }
907 }
908 # Set up for obj ID sequences, and obj ID reuse
909 # for shared classes using _ID
910 0 ▶ if ($$sh_cl{$flag_class}{'share'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sh_cl->{$flag_class}{"share"}) 0 0 0
911 0 my $reuse = $GBL{'id'}{'reuse'};
912 0 ▶ if (exists($$id_subs{$flag_class}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $id_subs->{$flag_class} and $id_subs->{$flag_class}{"code"} == \&Object::InsideOut::_ID) 0 0 0
Condition0%0/3
exists $id_subs->{$flag_class} and $id_subs->{$flag_class}{"code"} == \&Object::InsideOut::_ID
!ll&&!rl&&r
000
MC/DC0%0/2
exists $id_subs->{$flag_class} and $id_subs->{$flag_class}{"code"} == \&Object::InsideOut::_ID
exists $id_subs->{$flag_class} $id_subs->{$flag_class}{"code"} == \&Object::InsideOut::_ID
Truth table0%0/3
A and B
A= exists $id_subs->{$flag_class}B= $id_subs->{$flag_class}{"code"} == \&Object::InsideOut::_ID
ABresult
0X0
100
111
913 ($$id_subs{$flag_class}{'code'} == \&_ID))
914 {
915 0 my $share_tree = $$id_subs{$flag_class}{'pkg'};
916 0 ▶ if (! exists($$obj_ids{$share_tree})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $obj_ids->{$share_tree}) 0 0 0
917 0 $$obj_ids{$share_tree} = make_shared([]);
918 0 $$obj_ids{$share_tree}[0] = 0;
919 }
920 0 ▶ if (! exists($$reuse{$share_tree})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $reuse->{$share_tree}) 0 0 0
921 0 $$reuse{$share_tree} = make_shared([]);
922 }
923 0 my $r_tree = $$reuse{$share_tree};
924 0 ▶ if (! defined($$r_tree[0])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $r_tree->[0]) 0 0 0
925 0 $$r_tree[0] = make_shared([]);
926 }
927 }
928 }
929 }
930  
931 # Set up for shared object tracking
932 0 ▶ if (! exists($GBL{'share'}{'obj'}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $GBL{"share"}{"obj"} and $] < "5.008009" || $threads::shared::VERSION lt "1.15") 0 0 0
Condition0%0/6
not exists $GBL{"share"}{"obj"} and $] < "5.008009" || $threads::shared::VERSION lt "1.15"
!ll&&!rl&&r
000
$] < "5.008009" or $threads::shared::VERSION lt "1.15"
l!l&&r!l&&!r
000
MC/DC0%0/3
not exists $GBL{"share"}{"obj"} and $] < "5.008009" || $threads::shared::VERSION lt "1.15"
not exists $GBL{"share"}{"obj"} $] < "5.008009" $threads::shared::VERSION lt "1.15"
Truth table0%0/4
not(A) and B or C
A= not exists $GBL{"share"}{"obj"}B= $] < "5.008009"C= $threads::shared::VERSION lt "1.15"
ABCresult
0XX0
1000
11X1
1011
933 (($] < 5.008009) || ($threads::shared::VERSION lt '1.15')))
934 {
935 0 $GBL{'share'}{'obj'} = make_shared({});
936 }
937 }
938  
939 # Process field attributes
940 136 process_fields();
941  
942 # Implement ->isa()/->can() with :AutoMethods
943 136 ▶ if (%{$GBL{'sub'}{'auto'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$GBL{"sub"}{"auto"};}) 5 131 136
944 5 install_UNIVERSAL();
945 }
946  
947 # Implement overload (-ify) operators
948 136 ▶ if (exists($GBL{'sub'}{'ol'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GBL{"sub"}{"ol"}) 4 132 136
949 4 generate_OVERLOAD(\%GBL);
950 }
951  
952 # Add metadata for methods
953 136 my $meta = $GBL{'meta'}{'add'};
954 136 ▶ if (my $meta_m = delete($GBL{'meta'}{'method'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meta_m = delete $GBL{"meta"}{"method"}) 44 92 136
955 44 ▶ while (my $info = shift(@{$meta_m})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = shift @{$meta_m;}) 396 44 440
956 396 ▶ $$info{'name'} ||= sub_name($$info{'code'}, ':METHOD', $$info{'loc'});
Condition33%1/3
$info->{"name"} ||= sub_name($info->{"code"}, ":METHOD", $info->{"loc"})
l!l&&r!l&&!r
03960
MC/DC0%0/2
$info->{"name"} ||= sub_name($info->{"code"}, ":METHOD", $info->{"loc"})
$info->{"name"} sub_name($info->{"code"}, ":METHOD", $info->{"loc"})
Truth table33%1/3
A ||= B
A= $info->{"name"}B= sub_name($info->{"code"}, ":METHOD", $info->{"loc"})
ABresult
1X1
011
000
957 396 $$meta{$$info{'pkg'}}{$$info{'name'}}{'kind'} = $$info{'kind'};
958 }
959 }
960  
961 # Add metadata for subroutines
962 136 ▶ if (my $meta_s = delete($GBL{'meta'}{'subr'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $meta_s = delete $GBL{"meta"}{"subr"}) 53 83 136
963 53 ▶ while (my $info = shift(@{$meta_s})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = shift @{$meta_s;}) 1515 53 1568
964 1515 ▶ $$info{'name'} ||= sub_name($$info{'code'}, ':SUB', $$info{'loc'});
Condition33%1/3
$info->{"name"} ||= sub_name($info->{"code"}, ":SUB", $info->{"loc"})
l!l&&r!l&&!r
015150
MC/DC0%0/2
$info->{"name"} ||= sub_name($info->{"code"}, ":SUB", $info->{"loc"})
$info->{"name"} sub_name($info->{"code"}, ":SUB", $info->{"loc"})
Truth table33%1/3
A ||= B
A= $info->{"name"}B= sub_name($info->{"code"}, ":SUB", $info->{"loc"})
ABresult
1X1
011
000
965 1515 $$meta{$$info{'pkg'}}{$$info{'name'}}{'hidden'} = 1;
966 }
967 }
968  
969 # Implement merged argument methods
970 136 ▶ if (my $merge = delete($GBL{'merge'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $merge = delete $GBL{"merge"}) 46 90 136
971 46 ▶ while (my $info = shift(@{$merge})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = shift @{$merge;}) 58 46 104
972 58 ▶ $$info{'name'} ||= sub_name($$info{'code'}, ':MergeArgs', $$info{'loc'});
Condition33%1/3
$info->{"name"} ||= sub_name($info->{"code"}, ":MergeArgs", $info->{"loc"})
l!l&&r!l&&!r
0580
MC/DC0%0/2
$info->{"name"} ||= sub_name($info->{"code"}, ":MergeArgs", $info->{"loc"})
$info->{"name"} sub_name($info->{"code"}, ":MergeArgs", $info->{"loc"})
Truth table33%1/3
A ||= B
A= $info->{"name"}B= sub_name($info->{"code"}, ":MergeArgs", $info->{"loc"})
ABresult
1X1
011
000
973 58 my $pkg = $$info{'pkg'};
974 58 my $name = $$info{'name'};
975  
976 58 my $new_wrap = wrap_MERGE_ARGS($$info{'wrap'});
977 58 *{$pkg.'::'.$name} = $new_wrap;
978 58 $$info{'wrap'} = $new_wrap;
979  
980 58 $$meta{$pkg}{$name}{'merge_args'} = 1;
981 }
982 }
983  
984 # Implement restricted methods - only callable within hierarchy
985 136 ▶ if (my $restr = delete($GBL{'perm'}{'restr'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $restr = delete $GBL{"perm"}{"restr"}) 4 132 136
986 4 ▶ while (my $info = shift(@{$restr})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = shift @{$restr;}) 9 4 13
987 9 ▶ $$info{'name'} ||= sub_name($$info{'code'}, ':RESTRICTED', $$info{'loc'});
Condition66%2/3
$info->{"name"} ||= sub_name($info->{"code"}, ":RESTRICTED", $info->{"loc"})
l!l&&r!l&&!r
270
MC/DC0%0/2
$info->{"name"} ||= sub_name($info->{"code"}, ":RESTRICTED", $info->{"loc"})
$info->{"name"} sub_name($info->{"code"}, ":RESTRICTED", $info->{"loc"})
Truth table66%2/3
A ||= B
A= $info->{"name"}B= sub_name($info->{"code"}, ":RESTRICTED", $info->{"loc"})
ABresult
1X1
011
000
988 9 my $pkg = $$info{'pkg'};
989 9 my $name = $$info{'name'};
990  
991 9 ▶ my $exempt = [ grep {$_} split(/[,'\s]+/, $$info{'exempt'} || '') ];
Condition100%2/2
$info->{'exempt'} || ''
l!l
36
MC/DC100%1/1
$info->{'exempt'} || ''
$info->{'exempt'}
Truth table100%2/2
A
A= $info->{'exempt'}
Aresult
11
00
992  
993 9 my $new_wrap = wrap_RESTRICTED($pkg, $name, $$info{'wrap'}, $exempt);
994 9 *{$pkg.'::'.$name} = $new_wrap;
995 9 $$info{'wrap'} = $new_wrap;
996  
997 9 $$meta{$pkg}{$name}{'restricted'} = 1;
998 }
999 }
1000  
1001 # Implement private methods - only callable from class itself
1002 136 ▶ if (my $priv = delete($GBL{'perm'}{'priv'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $priv = delete $GBL{"perm"}{"priv"}) 55 81 136
1003 55 ▶ while (my $info = shift(@{$priv})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = shift @{$priv;}) 1168 55 1223
1004 1168 ▶ $$info{'name'} ||= sub_name($$info{'code'}, ':PRIVATE', $$info{'loc'});
Condition66%2/3
$info->{"name"} ||= sub_name($info->{"code"}, ":PRIVATE", $info->{"loc"})
l!l&&r!l&&!r
1157110
MC/DC0%0/2
$info->{"name"} ||= sub_name($info->{"code"}, ":PRIVATE", $info->{"loc"})
$info->{"name"} sub_name($info->{"code"}, ":PRIVATE", $info->{"loc"})
Truth table66%2/3
A ||= B
A= $info->{"name"}B= sub_name($info->{"code"}, ":PRIVATE", $info->{"loc"})
ABresult
1X1
011
000
1005 1168 my $pkg = $$info{'pkg'};
1006 1168 my $name = $$info{'name'};
1007  
1008 1168 ▶ my $exempt = [ $pkg, grep {$_} split(/[,'\s]+/, $$info{'exempt'} || '') ];
Condition100%2/2
$info->{'exempt'} || ''
l!l
11167
MC/DC100%1/1
$info->{'exempt'} || ''
$info->{'exempt'}
Truth table100%2/2
A
A= $info->{'exempt'}
Aresult
11
00
1009  
1010 1168 my $new_wrap = wrap_PRIVATE($pkg, $name, $$info{'wrap'}, $exempt);
1011 1168 *{$pkg.'::'.$name} = $new_wrap;
1012 1168 $$info{'wrap'} = $new_wrap;
1013  
1014 1168 $$meta{$pkg}{$name}{'private'} = 1;
1015 }
1016 }
1017  
1018 # Implement hidden methods - no longer callable by name
1019 136 ▶ if (my $hide = delete($GBL{'perm'}{'hide'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hide = delete $GBL{"perm"}{"hide"}) 21 115 136
1020 21 ▶ while (my $info = shift(@{$hide})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = shift @{$hide;}) 36 21 57
1021 36 ▶ $$info{'name'} ||= sub_name($$info{'code'}, ':HIDDEN', $$info{'loc'});
Condition33%1/3
$info->{"name"} ||= sub_name($info->{"code"}, ":HIDDEN", $info->{"loc"})
l!l&&r!l&&!r
0360
MC/DC0%0/2
$info->{"name"} ||= sub_name($info->{"code"}, ":HIDDEN", $info->{"loc"})
$info->{"name"} sub_name($info->{"code"}, ":HIDDEN", $info->{"loc"})
Truth table33%1/3
A ||= B
A= $info->{"name"}B= sub_name($info->{"code"}, ":HIDDEN", $info->{"loc"})
ABresult
1X1
011
000
1022 36 my $pkg = $$info{'pkg'};
1023 36 my $name = $$info{'name'};
1024  
1025 36 *{$pkg.'::'.$name} = wrap_HIDDEN($pkg, $name);
1026  
1027 36 $$meta{$pkg}{$name}{'hidden'} = 1;
1028 }
1029 }
1030  
1031 # Implement cumulative methods
1032 136 ▶ if (exists($GBL{'sub'}{'cumu'}{'new'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GBL{"sub"}{"cumu"}{"new"}) 1 135 136
1033 1 generate_CUMULATIVE(\%GBL);
1034 }
1035  
1036 # Implement chained methods
1037 136 ▶ if (exists($GBL{'sub'}{'chain'}{'new'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GBL{"sub"}{"chain"}{"new"}) 4 132 136
1038 4 generate_CHAINED(\%GBL);
1039 }
1040  
1041 # Export methods
1042 136 my @export = @{$GBL{'export'}};
1043 136 my $trees_bu = $GBL{'tree'}{'bu'};
1044 136 foreach my $pkg (keys(%{$trees})) {
1045 EXPORT:
1046 282 ▶ foreach my $sym (@export, ($pkg->isa('Storable'))
Branch: 1 branch
BranchTrueFalseTotal
$pkg->isa('Storable') ? : 9 273 282
1047 ? (qw(STORABLE_freeze STORABLE_thaw))
1048 : ())
1049 {
1050 1523 my $full_sym = $pkg.'::'.$sym;
1051 # Only export if method doesn't already exist,
1052 # and not overridden in a parent class
1053 1523 ▶ if (! *{$full_sym}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (*{$full_sym;}{"CODE"}) 739 784 1523
1054 739 foreach my $class (@{$$trees_bu{$pkg}}) {
1055 1323 my $class_sym = $class.'::'.$sym;
1056 1323 ▶ if (*{$class_sym}{CODE} &&
Branch: 1 branch
BranchTrueFalseTotal
if (*{$class_sym;}{"CODE"} and *{$class_sym;}{"CODE"} != \&{$sym;}) 0 1323 1323
Condition66%2/3
*{$class_sym;}{"CODE"} and *{$class_sym;}{"CODE"} != \&{$sym;}
!ll&&!rl&&r
10143090
MC/DC0%0/2
*{$class_sym;}{"CODE"} and *{$class_sym;}{"CODE"} != \&{$sym;}
*{$class_sym;}{"CODE"} *{$class_sym;}{"CODE"} != \&{$sym;}
Truth table66%2/3
A and B
A= *{$class_sym;}{"CODE"}B= *{$class_sym;}{"CODE"} != \&{$sym;}
ABresult
0X0
100
111
1057 309 (*{$class_sym}{CODE} != \&{$sym}))
1058 {
1059 0 next EXPORT;
1060 }
1061 }
1062 739 *{$full_sym} = \&{$sym};
1063  
1064 # Add metadata
1065 739 ▶ if ($sym eq 'new') {
Branch: 5 branches
BranchTrueFalseTotal
if ($sym eq 'new') { } 132 607 739
elsif ($sym eq 'clone' or $sym eq 'dump') { } 150 457 607
elsif ($sym eq 'create_field') { } 0 457 457
elsif ($sym =~ /^STORABLE_/ or $sym eq 'AUTOLOAD') { } 19 438 457
elsif ($sym =~ /herit/ or $sym eq 'set') { } 164 274 438
1066 132 $$meta{$pkg}{'new'} = { 'kind' => 'constructor',
1067 'merge_args' => 1 };
1068  
1069 ▶ } elsif ($sym eq 'clone' || $sym eq 'dump') {
Condition100%3/3
$sym eq "clone" or $sym eq "dump"
l!l&&r!l&&!r
13713457
MC/DC100%2/2
$sym eq "clone" or $sym eq "dump"
$sym eq "clone" $sym eq "dump"
Truth table100%3/3
A or B
A= $sym eq "clone"B= $sym eq "dump"
ABresult
1X1
011
000
1070 150 $$meta{$pkg}{$sym}{'kind'} = 'object';
1071  
1072 } elsif ($sym eq 'create_field') {
1073 0 $$meta{$pkg}{$sym}{'kind'} = 'class';
1074  
1075 ▶ } elsif ($sym =~ /^STORABLE_/ || ($sym eq 'AUTOLOAD')) {
Condition100%3/3
$sym =~ /^STORABLE_/ or $sym eq "AUTOLOAD"
l!l&&r!l&&!r
613438
MC/DC100%2/2
$sym =~ /^STORABLE_/ or $sym eq "AUTOLOAD"
$sym =~ /^STORABLE_/ $sym eq "AUTOLOAD"
Truth table100%3/3
A or B
A= $sym =~ /^STORABLE_/B= $sym eq "AUTOLOAD"
ABresult
1X1
011
000
1076 19 $$meta{$pkg}{$sym}{'hidden'} = 1;
1077  
1078 ▶ } elsif ($sym =~ /herit/ || $sym eq 'set') {
Condition100%3/3
$sym =~ /herit/ or $sym eq "set"
l!l&&r!l&&!r
27137274
MC/DC100%2/2
$sym =~ /herit/ or $sym eq "set"
$sym =~ /herit/ $sym eq "set"
Truth table100%3/3
A or B
A= $sym =~ /herit/B= $sym eq "set"
ABresult
1X1
011
000
1079 164 $$meta{$pkg}{$sym} = { 'kind' => 'object',
1080 'restricted' => 1 };
1081 }
1082 }
1083 }
1084 }
1085  
1086 # Add accumulated metadata
1087 136 add_meta($meta);
1088 136 $GBL{'meta'}{'add'} = {};
1089 45 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1090  
1091  
1092 # Process attributes for field hashes/arrays including generating accessors
1093 sub process_fields :Sub(Private)
1094 {
1095 140 ▶ my $new = delete($GBL{'fld'}{'new'});
Subroutine process_fields: called CC=17 SCAR=31.8
Pod undocumented
1096 140 ▶ return if (! $new);
Branch: 1 branch
BranchTrueFalseTotal
unless $new 96 44 140
1097  
1098 # 'Want' module loaded?
1099 44 ▶ my $use_want = (defined($Want::VERSION) && ($Want::VERSION >= 0.12));
Condition66%2/3
defined $Want::VERSION && $Want::VERSION >= 0.12
!ll&&!rl&&r
4301
MC/DC50%1/2
defined $Want::VERSION && $Want::VERSION >= 0.12
defined $Want::VERSION $Want::VERSION >= 0.12
Truth table66%2/3
A && B
A= defined $Want::VERSIONB= $Want::VERSION >= 0.12
ABresult
0X0
100
111
1100  
1101 44 my $trees = $GBL{'tree'}{'td'};
1102 44 my $fld_refs = $GBL{'fld'}{'ref'};
1103 44 my $g_ho = $GBL{'hash_only'};
1104 44 my $do_ho = %{$g_ho};
1105  
1106 # Process field attributes
1107 44 foreach my $pkg (keys(%{$new})) {
1108 71 ▶ while (my $item = shift(@{$$new{$pkg}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $item = shift @{$$new{$pkg};}) 271 69 340
1109 271 my ($fld, $attr) = @{$item};
1110  
1111 # Verify not a 'hash field only' class
1112 271 ▶ if ((ref($fld) eq 'ARRAY') && $do_ho) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fld eq "ARRAY" and $do_ho) 2 269 271
Condition100%3/3
ref $fld eq "ARRAY" and $do_ho
!ll&&!rl&&r
362332
MC/DC100%2/2
ref $fld eq "ARRAY" and $do_ho
ref $fld eq "ARRAY" $do_ho
Truth table100%3/3
A and B
A= ref $fld eq "ARRAY"B= $do_ho
ABresult
0X0
100
111
1113 2 foreach my $ho (keys(%{$g_ho})) {
1114 3 foreach my $class (@{$$trees{$pkg}}) {
1115 5 ▶ if ($class eq $ho) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq $ho) 2 3 5
1116 my $loc = ((caller())[1] =~ /Dynamic/)
1117 ? [ (caller(2))[0..2] ]
1118 2 ▶ : $$g_ho{$ho};
Branch: 1 branch
BranchTrueFalseTotal
(caller())[1] =~ /Dynamic/ ? : 2 0 2
1119 2 OIO::Code->die(
1120 'location' => $loc,
1121 'message' => "Can't combine 'hash only' classes ($ho) with array-based classes ($class) in the same class tree",
1122 'Info' => "Class '$ho' was declared as ':hash_only', but class '$class' has array-based fields");
1123 }
1124 }
1125 }
1126 }
1127  
1128 # Share the field, if applicable
1129 269 ▶ if (is_sharing($pkg) && !threads::shared::is_shared($fld)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_sharing($pkg) and not threads::shared::is_shared($fld)) 0 269 269
Condition33%1/3
is_sharing($pkg) and not threads::shared::is_shared($fld)
!ll&&!rl&&r
26900
MC/DC0%0/2
is_sharing($pkg) and not threads::shared::is_shared($fld)
is_sharing($pkg) not threads::shared::is_shared($fld)
Truth table33%1/3
A and not(B)
A= is_sharing($pkg)B= not threads::shared::is_shared($fld)
ABresult
0X0
100
111
1130 # Preserve any contents
1131 0 my $contents = Object::InsideOut::Util::clone_shared($fld);
1132  
1133 # Share the field
1134 0 threads::shared::share($fld);
1135  
1136 # Restore contents
1137 0 ▶ if ($contents) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents) 0 0 0
1138 0 ▶ if (ref($fld) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fld eq 'HASH') { } 0 0 0
1139 0 %{$fld} = %{$contents};
1140 } else {
1141 0 @{$fld} = @{$contents};
1142 }
1143 }
1144 }
1145  
1146 # Process any accessor declarations
1147 269 ▶ if ($attr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr) 269 0 269
1148 269 create_accessors($pkg, $fld, $attr, $use_want);
1149 }
1150  
1151 # Save field ref
1152 269 ▶ if (! grep { $_ == $fld } @{$$fld_refs{$pkg}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ == $fld;} @{$$fld_refs{$pkg};}) 163 106 269
1153 163 push(@{$$fld_refs{$pkg}}, $fld);
1154 }
1155 }
1156 }
1157 45 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1158  
1159  
1160 # Normalize the :InitArgs hash
1161 sub normalize :Sub
1162 {
1163 68 ▶ my $hash = $_[$#_];
Subroutine normalize: called CC=12 SCAR=24.9
Pod undocumented
1164 68 ▶ if (ref($hash) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash ne "HASH") 0 68 68
1165 0 OIO::Args->die(
1166 'message' => 'Argument is not a hash ref',
1167 'Usage' => q/Object::InsideOut::normalize($hash)/);
1168 }
1169  
1170 68 foreach my $arg (keys(%{$hash})) {
1171 134 my $spec = $$hash{$arg};
1172 134 ▶ next if (ref($spec) ne 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $spec ne "HASH" 37 97 134
1173 97 foreach my $opt (keys(%{$spec})) {
1174 210 ▶ if ($opt =~ qr/^DEF(?:AULTs?)?$/i) {
Branch: 6 branches
BranchTrueFalseTotal
if ($opt =~ qr/^DEF(?:AULTs?)?$/i) { } 28 182 210
elsif ($opt =~ qr/^FIELD$/i) { } 46 136 182
elsif ($opt =~ qr/^(?:MAND|REQ)/i) { } 2 134 136
elsif ($opt =~ qr/^PRE/i) { } 3 131 134
elsif ($opt =~ qr/^RE(?:GEXp?)?$/i) { } 13 118 131
elsif ($opt =~ qr/^TYPE$/i) { } 14 104 118
1175 28 $$spec{'_D'} = $$spec{$opt};
1176 } elsif ($opt =~ qr/^FIELD$/i) {
1177 46 $$spec{'_F'} = $$spec{$opt};
1178 } elsif ($opt =~ qr/^(?:MAND|REQ)/i) {
1179 2 $$spec{'_M'} = $$spec{$opt};
1180 } elsif ($opt =~ qr/^PRE/i) {
1181 3 $$spec{'_P'} = $$spec{$opt};
1182 } elsif ($opt =~ qr/^RE(?:GEXp?)?$/i) {
1183 # Turn into an actual 'Regexp', if needed
1184 $$spec{'_R'} = (ref($$spec{$opt}) eq 'Regexp')
1185 13 ▶ ? $$spec{$opt}
Branch: 1 branch
BranchTrueFalseTotal
ref $spec->{$opt} eq 'Regexp' ? : 13 0 13
1186 : qr/^$$spec{$opt}$/;
1187 } elsif ($opt =~ qr/^TYPE$/i) {
1188 14 $$spec{'_T'} = $$spec{$opt};
1189 }
1190 }
1191 }
1192 68 $$hash{' '} = undef;
1193  
1194 68 return ($hash);
1195 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1196  
1197  
1198 ### Thread-Shared Object Support ###
1199  
1200 # Set a class as thread-sharing
1201 sub set_sharing :Sub(Private)
1202 {
1203 0 ▶ my ($class, $sharing, $file, $line) = @_;
Subroutine set_sharing: not called CC=8 SCAR=42.8
Pod undocumented
1204 0 ▶ $sharing = ($sharing) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$sharing ? : 0 0 0
1205  
1206 0 my $sh_cl = $GBL{'share'}{'cl'};
1207 0 ▶ if (exists($$sh_cl{$class})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $sh_cl->{$class}) { } 0 0 0
1208 0 ▶ if ($$sh_cl{$class}{'share'} != $sharing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sh_cl->{$class}{"share"} != $sharing) 0 0 0
1209 0 my (@loc, $nfile, $nline);
1210 0 ▶ if ($sharing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sharing) { } 0 0 0
1211 0 @loc = ($class, $file, $line);
1212 0 $nfile = $$sh_cl{$class}{'file'};
1213 0 $nline = $$sh_cl{$class}{'line'};
1214 } else {
1215 @loc = ($class,
1216 $$sh_cl{$class}{'file'},
1217 0 $$sh_cl{$class}{'line'});
1218 0 ($nfile, $nline) = ($file, $line);
1219 }
1220 0 OIO::Code->die(
1221 'location' => \@loc,
1222 'message' => "Can't combine thread-sharing and non-sharing instances of a class in the same application",
1223 'Info' => "Class '$class' was declared as sharing in '$file' line $line, but was declared as non-sharing in '$nfile' line $nline");
1224 }
1225 } else {
1226 0 $$sh_cl{$class} = {
1227 share => $sharing,
1228 file => $file,
1229 line => $line,
1230 };
1231 # Set up equality via overload
1232 0 ▶ if ($sharing && $threads::shared::threads_shared
Branch: 1 branch
BranchTrueFalseTotal
if ($sharing and $threads::shared::threads_shared and $threads::shared::VERSION ge "0.95") 0 0 0
Condition0%0/6
$sharing and $threads::shared::threads_shared and $threads::shared::VERSION ge "0.95"
!ll&&!rl&&r
000
$sharing and $threads::shared::threads_shared
!ll&&!rl&&r
000
MC/DC0%0/3
$sharing and $threads::shared::threads_shared and $threads::shared::VERSION ge "0.95"
$sharing $threads::shared::threads_shared $threads::shared::VERSION ge "0.95"
Truth table0%0/4
A and B and C
A= $sharingB= $threads::shared::threads_sharedC= $threads::shared::VERSION ge "0.95"
ABCresult
0XX0
10X0
1100
1111
1233 && $threads::shared::VERSION ge '0.95')
1234 {
1235 0 push(@{$GBL{'sub'}{'ol'}}, { 'pkg' => $class, 'ify' => 'EQUATE' });
1236 }
1237 }
1238 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1239  
1240  
1241 # Determines if a class's objects are shared between threads
1242 sub is_sharing :Sub(Private)
1243 {
1244 1172 ▶ return if ! $GBL{'share'}{'ok'};
Subroutine is_sharing: called CC=3 SCAR=19.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless $GBL{"share"}{"ok"} 1172 0 1172
1245 0 my $class = $_[0];
1246 0 my $sh_cl = $GBL{'share'}{'cl'};
1247 0 ▶ return (exists($$sh_cl{$class}) && $$sh_cl{$class}{'share'});
Condition0%0/3
exists $sh_cl->{$class} && $sh_cl->{$class}{'share'}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $sh_cl->{$class} && $sh_cl->{$class}{'share'}
exists $sh_cl->{$class} $sh_cl->{$class}{'share'}
Truth table0%0/3
A && B
A= exists $sh_cl->{$class}B= $sh_cl->{$class}{'share'}
ABresult
0X0
100
111
1248 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1249  
1250  
1251 ### Thread Cloning Support ###
1252  
1253 sub CLONE
1254 {
1255 # Don't execute when called for sub-classes
1256 0 ▶ return if ($_[0] ne 'Object::InsideOut');
Subroutine CLONE: not called CC=25 SCAR=64.8
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] ne "Object::InsideOut" 0 0 0
1257  
1258 # Don't execute twice for same thread
1259 0 my $tid;
1260 0 ▶ if ($threads::threads) {
Branch: 1 branch
BranchTrueFalseTotal
if ($threads::threads) { } 0 0 0
1261 0 $tid = threads->tid();
1262 0 ▶ return if ($GBL{'tid'} == $tid);
Branch: 1 branch
BranchTrueFalseTotal
if $GBL{"tid"} == $tid 0 0 0
1263 0 $GBL{'tid'} = $tid;
1264 } else {
1265 # Pseudo-fork
1266 0 ▶ return if (exists($GBL{'pids'}{$$}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $GBL{"pids"}{$$} 0 0 0
1267 0 $GBL{'pids'}{$$} = undef;
1268 0 $tid = $GBL{'tid'};
1269 }
1270  
1271 # Check for delayed threads::shared usage
1272 0 ▶ if ($threads::shared::threads_shared && ! $GBL{'share'}{'ok'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($threads::shared::threads_shared and not $GBL{"share"}{"ok"}) 0 0 0
Condition0%0/3
$threads::shared::threads_shared and not $GBL{"share"}{"ok"}
!ll&&!rl&&r
000
MC/DC0%0/2
$threads::shared::threads_shared and not $GBL{"share"}{"ok"}
$threads::shared::threads_shared not $GBL{"share"}{"ok"}
Truth table0%0/3
A and not(B)
A= $threads::shared::threads_sharedB= not $GBL{"share"}{"ok"}
ABresult
0X0
100
111
1273 0 OIO::Code->die(
1274 'message' => q/'threads::shared' imported after Object::InsideOut initialized/,
1275 'Info' => q/Add 'use threads::shared;' to the start of your application code/);
1276 }
1277  
1278 # Process thread-shared objects
1279 0 ▶ if (exists($GBL{'share'}{'obj'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GBL{"share"}{"obj"}) 0 0 0
1280 0 my $sh_obj = $GBL{'share'}{'obj'};
1281 0 lock($sh_obj);
1282  
1283 # Add thread ID to every object in the thread tracking registry
1284 0 foreach my $class (keys(%{$sh_obj})) {
1285 0 foreach my $oid (keys(%{$$sh_obj{$class}})) {
1286 0 push(@{$$sh_obj{$class}{$oid}}, $tid);
1287 }
1288 }
1289 }
1290  
1291 # Fix field references
1292 0 my $g_fld = $GBL{'fld'};
1293 0 my $regen = $$g_fld{'regen'};
1294 0 $$g_fld{'type'} = { map { $_->[0] => $_->[1] } @{$$regen{'type'}} };
1295 0 $$g_fld{'weak'} = { map { $_ => 1 } @{$$regen{'weak'}} };
1296 0 $$g_fld{'deep'} = { map { $_ => 1 } @{$$regen{'deep'}} };
1297  
1298 # Process non-thread-shared objects
1299 0 my $g_obj = $GBL{'obj'};
1300 0 my $trees = $GBL{'tree'}{'td'};
1301 0 my $id_subs = $GBL{'sub'}{'id'};
1302 0 my $fld_ref = $$g_fld{'ref'};
1303 0 my $weak = $$g_fld{'weak'};
1304 0 my $repl_subs = $GBL{'sub'}{'repl'};
1305 0 my $do_repl = keys(%{$repl_subs});
1306 0 foreach my $class (keys(%{$g_obj})) {
1307 0 my $obj_cl = $$g_obj{$class};
1308  
1309 # Get class tree
1310 0 my @tree = @{$$trees{$class}};
1311  
1312 # Get the ID sub for this class, if any
1313 0 my $id_sub = $$id_subs{$class}{'code'};
1314  
1315 # Get any replication handlers
1316 0 my @repl;
1317 0 ▶ if ($do_repl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_repl) 0 0 0
1318 0 @repl = grep { $_ } map { $$repl_subs{$_} } @tree;
1319 }
1320  
1321 # Process each object in the class
1322 0 foreach my $old_id (keys(%{$obj_cl})) {
1323 0 my $obj;
1324 0 ▶ if ($id_sub == \&_ID) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_sub == \&Object::InsideOut::_ID) { } 0 0 0
1325 # Objects using internal ID sub keep their same ID
1326 0 $obj = $$obj_cl{$old_id};
1327  
1328 # Set 'next object ID'
1329 0 my $pkg = $GBL{'sub'}{'id'}{$class}{'pkg'};
1330 0 my $g_id = $GBL{'id'}{'obj'}{$pkg};
1331 0 ▶ if (! $$g_id[$tid] || ($$g_id[$tid] < $$obj)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $g_id->[$tid] or $g_id->[$tid] < $$obj) 0 0 0
Condition0%0/3
not $g_id->[$tid] or $g_id->[$tid] < $$obj
l!l&&r!l&&!r
000
MC/DC0%0/2
not $g_id->[$tid] or $g_id->[$tid] < $$obj
not $g_id->[$tid] $g_id->[$tid] < $$obj
Truth table0%0/3
not(A) or B
A= not $g_id->[$tid]B= $g_id->[$tid] < $$obj
ABresult
1X1
011
000
1332 0 $$g_id[$tid] = $$obj;
1333 }
1334  
1335 } else {
1336 # Get cloned object associated with old ID
1337 0 $obj = delete($$obj_cl{$old_id});
1338  
1339 # Unlock the object
1340 0 ▶ Internals::SvREADONLY($$obj, 0) if ($] >= 5.008003);
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.008003" 0 0 0
1341  
1342 # Replace the old object ID with a new one
1343 0 local $SIG{'__DIE__'} = 'OIO::trap';
1344 0 $$obj = $id_sub->($class);
1345  
1346 # Lock the object again
1347 0 ▶ Internals::SvREADONLY($$obj, 1) if ($] >= 5.008003);
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.008003" 0 0 0
1348  
1349 # Update the keys of the field arrays/hashes
1350 # with the new object ID
1351 0 foreach my $pkg (@tree) {
1352 0 foreach my $fld (@{$$fld_ref{$pkg}}) {
1353 0 ▶ if (ref($fld) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fld eq 'HASH') { } 0 0 0
1354 0 $$fld{$$obj} = delete($$fld{$old_id});
1355 0 ▶ if ($$weak{'weak'}{$fld}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($weak->{"weak"}{$fld}) 0 0 0
1356 0 Scalar::Util::weaken($$fld{$$obj});
1357 }
1358 } else {
1359 0 $$fld[$$obj] = $$fld[$old_id];
1360 0 undef($$fld[$old_id]);
1361 0 ▶ if ($$weak{$fld}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($weak->{$fld}) 0 0 0
1362 0 Scalar::Util::weaken($$fld[$$obj]);
1363 }
1364 }
1365 }
1366 }
1367  
1368 # Resave weakened reference to object
1369 0 Scalar::Util::weaken($$obj_cl{$$obj} = $obj);
1370 }
1371  
1372 # Dispatch any special replication handling
1373 0 ▶ if (@repl) {
Branch: 1 branch
BranchTrueFalseTotal
if (@repl) 0 0 0
1374 0 my $pseudo_object = \do{ my $scalar = $old_id; };
1375 0 foreach my $repl (@repl) {
1376 0 local $SIG{'__DIE__'} = 'OIO::trap';
1377 0 $repl->($pseudo_object, $obj, 'CLONE');
1378 }
1379 }
1380 }
1381 }
1382 }
1383  
1384  
1385 ### Object Methods ###
1386  
1387 # Helper subroutine to create a new 'bare' object
1388 sub _obj :Sub(Private)
1389 {
1390 183 ▶ my $class = shift;
Subroutine _obj: called CC=5 SCAR=26.1
1391  
1392 # Create a new 'bare' object
1393 183 my $self = create_object($class, $GBL{'sub'}{'id'}{$class}{'code'});
1394  
1395 # Thread support
1396 183 ▶ if (is_sharing($class)) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_sharing($class)) { } 0 183 183
elsif ($threads::threads) { } 0 183 183
1397 0 threads::shared::share($self);
1398  
1399 # Add thread tracking list for this thread-shared object
1400 0 ▶ if (exists($GBL{'share'}{'obj'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GBL{"share"}{"obj"}) 0 0 0
1401 0 my $sh_obj = $GBL{'share'}{'obj'};
1402 0 lock($sh_obj);
1403 0 ▶ if (exists($$sh_obj{$class})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $sh_obj->{$class}) { } 0 0 0
1404 0 $$sh_obj{$class}{$$self} = make_shared([ $GBL{'tid'} ]);
1405 } else {
1406 0 $$sh_obj{$class} = make_shared({ $$self => [ $GBL{'tid'} ] });
1407 }
1408 }
1409  
1410 } elsif ($threads::threads) {
1411 # Add non-thread-shared object to thread cloning list
1412 0 Scalar::Util::weaken($GBL{'obj'}{$class}{$$self} = $self);
1413 }
1414  
1415 183 return ($self);
1416 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1417  
1418  
1419 # Extracts specified args from those given
1420 sub _args :Sub(Private)
1421 {
1422 105 ▶ my ($class,
Subroutine _args: called CC=52 SCAR=42.6
1423 $self, # Object being initialized with args
1424 $spec, # Hash ref of arg specifiers
1425 $args, # Hash ref of args
1426 $used) # Hash ref of used args
1427 = @_;
1428  
1429 # Ensure :InitArgs hash is normalized
1430 105 ▶ if (! exists($$spec{' '})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $spec->{" "}) 46 59 105
1431 46 normalize($spec);
1432 }
1433  
1434 # Extract arg-matching regexs from the specifiers
1435 105 my %regex;
1436 105 ▶ while (my ($key, $val) = each(%{$spec})) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$spec;}) 385 105 490
1437 385 ▶ next if ($key eq ' ');
Branch: 1 branch
BranchTrueFalseTotal
if $key eq " " 105 280 385
1438 280 ▶ $regex{$key} = (ref($val) eq 'HASH') ? $$val{'_R'} : $val;
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'HASH' ? : 262 18 280
1439 }
1440  
1441 # Search for specified args
1442 105 my %found = ();
1443 105 my $add_used = $used;
1444 EXTRACT: {
1445 # Find arguments using regex's
1446 105 foreach my $key (keys(%regex)) {
1447 305 my $regex = $regex{$key};
1448 305 ▶ my ($value, $arg) = ($regex) ? hash_re($args, $regex) : ($$args{$key}, $key);
Branch: 1 branch
BranchTrueFalseTotal
$regex ? : 30 275 305
1449 305 ▶ if (defined($found{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $found{$key}) { } 7 298 305
1450 7 ▶ if (defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 7 7
1451 0 $found{$key} = $value;
1452 }
1453 } else {
1454 298 $found{$key} = $value;
1455 }
1456 305 ▶ if (defined($arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) 286 19 305
1457 286 $$add_used{$arg} = undef;
1458 }
1459 }
1460  
1461 # Check for class-specific argument hash ref
1462 115 ▶ if (exists($$args{$class})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{$class}) 10 105 115
1463 10 $args = $$args{$class};
1464 10 ▶ if (ref($args) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args ne "HASH") 0 10 10
1465 0 OIO::Args->die(
1466 'message' => "Bad class initializer for '$class'",
1467 'Usage' => q/Class initializers must be a hash ref/);
1468 }
1469 10 $$add_used{$class} = {};
1470 10 $add_used = $$add_used{$class};
1471 # Loop back to process class-specific arguments
1472 10 redo EXTRACT;
1473 }
1474 }
1475  
1476 # Check on what we've found
1477 CHECKIT:
1478 105 foreach my $key (keys(%{$spec})) {
1479 353 my $spec_item = $$spec{$key};
1480 # No specs to check
1481 353 ▶ if (ref($spec_item) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec_item ne "HASH") 116 237 353
1482 # The specifier entry was just 'key => regex'. If 'key' is not in
1483 # the args, the we need to remove the 'undef' entry in the found
1484 # args hash.
1485 116 ▶ if (! defined($found{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $found{$key}) 103 13 116
1486 103 delete($found{$key});
1487 }
1488 116 next CHECKIT;
1489 }
1490  
1491 # Preprocess the argument
1492 237 ▶ if (my $pre = $$spec_item{'_P'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pre = $spec_item->{"_P"}) 3 234 237
1493 3 ▶ if (ref($pre) ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pre ne "CODE") 0 3 3
1494 0 OIO::Code->die(
1495 'message' => q/Can't handle argument/,
1496 'Info' => "'Preprocess' is not a code ref for initializer '$key' for class '$class'");
1497 }
1498  
1499 3 my (@errs);
1500 3 ▶ local $SIG{'__WARN__'} = sub { push(@errs, @_); };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1501 3 eval {
1502 3 local $SIG{'__DIE__'};
1503 3 $found{$key} = $pre->($class, $key, $spec_item, $self, $found{$key})
1504 };
1505 3 ▶ if ($@ || @errs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or @errs) 0 3 3
Condition33%1/3
$@ or @errs
l!l&&r!l&&!r
003
MC/DC0%0/2
$@ or @errs
$@ @errs
Truth table33%1/3
A or B
A= $@B= @errs
ABresult
1X1
011
000
1506 0 ▶ my ($err) = split(/ at /, $@ || join(" | ", @errs));
Condition0%0/3
$@ || join(' | ', @errs)
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || join(' | ', @errs)
$@ join(' | ', @errs)
Truth table0%0/3
A || B
A= $@B= join(' | ', @errs)
ABresult
1X1
011
000
1507 0 OIO::Code->die(
1508 'message' => "Problem with preprocess routine for initializer '$key' for class '$class",
1509 'Error' => $err);
1510 }
1511 }
1512  
1513 # Handle args not found
1514 237 ▶ if (! defined($found{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $found{$key}) 147 90 237
1515 # Complain if mandatory
1516 147 ▶ if ($$spec_item{'_M'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec_item->{"_M"}) 0 147 147
1517 0 OIO::Args->die(
1518 'message' => "Missing mandatory initializer '$key' for class '$class'");
1519 }
1520  
1521 # Assign default value
1522 147 ▶ if (exists($$spec_item{'_D'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $spec_item->{"_D"}) 66 81 147
1523 66 ▶ if (ref($$spec_item{'_D'}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec_item->{'_D'} eq 'CODE') { } 35 31 66
1524 35 $found{$key} = $$spec_item{'_D'}->($self);
1525 } else {
1526 31 $found{$key} = Object::InsideOut::Util::clone($$spec_item{'_D'});
1527 }
1528 }
1529  
1530 # If no default, then remove it from the found args hash
1531 147 ▶ if (! defined($found{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $found{$key}) 81 66 147
1532 81 delete($found{$key});
1533 81 next CHECKIT;
1534 }
1535 }
1536  
1537 # Check for correct type
1538 156 ▶ if (my $type = $$spec_item{'_T'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $spec_item->{"_T"}) 32 124 156
1539 32 my $subtype;
1540  
1541 # Custom type checking
1542 32 ▶ if (ref($type)) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $type) { } 16 16 32
elsif ($type =~ /^scalar$/i) { } 2 14 16
elsif ($type =~ /^num(?:ber|eric)?$/i) { } 4 10 14
elsif ($type =~ /^(?:list|array)\s*(?:\(\s*(\S+)\s*\))*$/i) { } 6 4 10
1543 16 ▶ if (ref($type) ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $type ne "CODE") 0 16 16
1544 0 OIO::Code->die(
1545 'message' => q/Can't validate argument/,
1546 'Info' => "'Type' is not a code ref or string for initializer '$key' for class '$class'");
1547 }
1548  
1549 16 my ($ok, @errs);
1550 16 ▶ local $SIG{'__WARN__'} = sub { push(@errs, @_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
1551 16 eval {
1552 16 local $SIG{'__DIE__'};
1553 16 $ok = $type->($found{$key})
1554 };
1555 16 ▶ if ($@ || @errs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or @errs) 2 14 16
Condition66%2/3
$@ or @errs
l!l&&r!l&&!r
0214
MC/DC50%1/2
$@ or @errs
$@ @errs
Truth table66%2/3
A or B
A= $@B= @errs
ABresult
1X1
011
000
1556 2 ▶ my ($err) = split(/ at /, $@ || join(" | ", @errs));
Condition33%1/3
$@ || join(' | ', @errs)
l!l&&r!l&&!r
020
MC/DC0%0/2
$@ || join(' | ', @errs)
$@ join(' | ', @errs)
Truth table33%1/3
A || B
A= $@B= join(' | ', @errs)
ABresult
1X1
011
000
1557 2 OIO::Code->die(
1558 'message' => "Problem with type check routine for initializer '$key' for class '$class",
1559 'Error' => $err);
1560 }
1561 14 ▶ if (! $ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 8 6 14
1562 8 OIO::Args->die(
1563 'message' => "Initializer '$key' for class '$class' failed type check: $found{$key}");
1564 }
1565 }
1566  
1567 # Is it supposed to be a scalar
1568 elsif ($type =~ /^scalar$/i) {
1569 2 ▶ if (ref($found{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $found{$key}) 1 1 2
1570 1 OIO::Args->die(
1571 'message' => "Bad value for initializer '$key': $found{$key}",
1572 'Usage' => "Initializer '$key' for class '$class' must be a scalar");
1573 }
1574 }
1575  
1576 # Is it supposed to be a number
1577 elsif ($type =~ /^num(?:ber|eric)?$/i) {
1578 4 ▶ if (! Scalar::Util::looks_like_number($found{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Scalar::Util::looks_like_number($found{$key})) 2 2 4
1579 2 OIO::Args->die(
1580 'message' => "Bad value for initializer '$key': $found{$key}",
1581 'Usage' => "Initializer '$key' for class '$class' must be a number");
1582 }
1583 }
1584  
1585 # For 'LIST', turn anything not an array ref into an array ref
1586 elsif ($type =~ /^(?:list|array)\s*(?:\(\s*(\S+)\s*\))*$/i) {
1587 6 ▶ if (defined($1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1) 0 6 6
1588 0 $subtype = $1;
1589 }
1590 6 ▶ if (ref($found{$key}) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $found{$key} ne "ARRAY") 3 3 6
1591 3 $found{$key} = [ $found{$key} ];
1592 }
1593 }
1594  
1595 # Otherwise, check for a specific class or ref type
1596 # Exact spelling and case required
1597 else {
1598 4 ▶ if ($type =~ /^(array|hash|scalar)(?:_?ref)?\s*(?:\(\s*(\S+)\s*\))*$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^(array|hash|scalar)(?:_?ref)?\s*(?:\(\s*(\S+)\s*\))*$/i) 4 0 4
1599 4 $type = uc($1);
1600 4 ▶ if (defined($2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $2) 2 2 4
1601 2 $subtype = $2;
1602 }
1603 }
1604 4 ▶ if (! is_it($found{$key}, $type)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_it($found{$key}, $type)) 0 4 4
1605 0 OIO::Args->die(
1606 'message' => "Bad value for initializer '$key': $found{$key}",
1607 'Usage' => "Initializer '$key' for class '$class' must be an object or ref of type '$type'");
1608 }
1609 }
1610  
1611 # Check type of each element in array
1612 19 ▶ if (defined($subtype)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subtype) 2 17 19
1613 2 ▶ if ($subtype =~ /^scalar$/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($subtype =~ /^scalar$/i) { } 0 2 2
elsif ($subtype =~ /^num(?:ber|eric)?$/i) { } 1 1 2
1614 # Scalar elements
1615 0 foreach my $elem (@{$found{$key}}) {
1616 0 ▶ if (ref($elem)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $elem) 0 0 0
1617 0 OIO::Args->die(
1618 'message' => "Bad value for initializer '$key': $elem",
1619 'Usage' => "Values making up initializer '$key' for class '$class' must be scalars");
1620 }
1621 }
1622 } elsif ($subtype =~ /^num(?:ber|eric)?$/i) {
1623 # Numeric elements
1624 1 foreach my $elem (@{$found{$key}}) {
1625 3 ▶ if (! Scalar::Util::looks_like_number($elem)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Scalar::Util::looks_like_number($elem)) 0 3 3
1626 0 OIO::Args->die(
1627 'message' => "Bad value for initializer '$key': $elem",
1628 'Usage' => "Values making up initializer '$key' for class '$class' must be numeric");
1629 }
1630 }
1631 } else {
1632 1 foreach my $elem (@{$found{$key}}) {
1633 2 ▶ if (! is_it($elem, $subtype)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_it($elem, $subtype)) 0 2 2
1634 0 OIO::Args->die(
1635 'message' => "Bad value for initializer '$key': $elem",
1636 'Usage' => "Values making up Initializer '$key' for class '$class' must be objects or refs of type '$subtype'");
1637 }
1638 }
1639 }
1640 }
1641 }
1642  
1643 # If the destination field is specified, then put it in, and remove it
1644 # from the found args hash.
1645 143 ▶ if (my $field = $$spec_item{'_F'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $field = $spec_item->{"_F"}) 135 8 143
1646 135 $self->set($field, delete($found{$key}));
1647 }
1648 }
1649  
1650 # Done - return remaining found args
1651 92 return (\%found);
1652 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1653  
1654  
1655 # Object Constructor
1656 sub new :MergeArgs
1657 {
1658 169 ▶ my ($thing, $all_args) = @_;
Subroutine new: called CC=34 SCAR=35.4
Pod documented
1659 169 ▶ my $class = ref($thing) || $thing;
Condition33%1/3
ref $thing || $thing
l!l&&r!l&&!r
01690
MC/DC0%0/2
ref $thing || $thing
ref $thing $thing
Truth table33%1/3
A || B
A= ref $thingB= $thing
ABresult
1X1
011
000
1660  
1661 # Can't call ->new() on this package
1662 169 ▶ if ($class eq 'Object::InsideOut') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "Object::InsideOut") 0 169 169
1663 0 OIO::Method->die('message' => q/'new' called on non-class 'Object::InsideOut'/);
1664 }
1665  
1666 # Perform package initialization, if required
1667 169 initialize();
1668  
1669 # Create a new 'bare' object
1670 169 my $self = _obj($class);
1671  
1672 # Object initialization activity caching
1673 169 my $have_cache = exists($GBL{'cache'}{$class});
1674 169 ▶ my %cache = ($have_cache) ? %{$GBL{'cache'}{$class}}
Branch: 1 branch
BranchTrueFalseTotal
$have_cache ? : 80 89 169
1675 : ( 'pre' => 0, 'def' => 0 );
1676  
1677 # Execute pre-initialization subroutines
1678 169 ▶ if ($cache{'pre'} || ! $have_cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache{"pre"} or not $have_cache) 91 78 169
Condition100%3/3
$cache{"pre"} or not $have_cache
l!l&&r!l&&!r
28978
MC/DC100%2/2
$cache{"pre"} or not $have_cache
$cache{"pre"} not $have_cache
Truth table100%3/3
A or not(B)
A= $cache{"pre"}B= not $have_cache
ABresult
1X1
011
000
1679 91 my $preinit_subs = $GBL{'sub'}{'pre'};
1680 91 ▶ if (%{$preinit_subs}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$preinit_subs;}) 4 87 91
1681 4 foreach my $pkg (@{$GBL{'tree'}{'bu'}{$class}}) {
1682 8 ▶ if (my $preinit = $$preinit_subs{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $preinit = $preinit_subs->{$pkg}) 4 4 8
1683 4 local $SIG{'__DIE__'} = 'OIO::trap';
1684 4 $self->$preinit($all_args);
1685 4 ▶ if ($have_cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_cache) { } 2 2 4
1686 2 ▶ last if (! (--$cache{'pre'}));
Branch: 1 branch
BranchTrueFalseTotal
unless --$cache{"pre"} 2 0 2
1687 } else {
1688 2 $cache{'pre'}++;
1689 }
1690 }
1691 }
1692 }
1693 }
1694  
1695 169 my $tree = $GBL{'tree'}{'td'}{$class};
1696  
1697 # Set any defaults
1698 169 ▶ if ($cache{'def'} || ! $have_cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache{"def"} or not $have_cache) 111 58 169
Condition100%3/3
$cache{"def"} or not $have_cache
l!l&&r!l&&!r
228958
MC/DC100%2/2
$cache{"def"} or not $have_cache
$cache{"def"} not $have_cache
Truth table100%3/3
A or not(B)
A= $cache{"def"}B= not $have_cache
ABresult
1X1
011
000
1699 111 foreach my $pkg (@{$tree}) {
1700 175 ▶ if (my $def = $GBL{'fld'}{'def'}{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $def = $GBL{"fld"}{"def"}{$pkg}) 28 147 175
1701 $self->set($_->[0], $_->[1]->($self))
1702 28 foreach (@{$def});
1703 28 ▶ if ($have_cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_cache) { } 22 6 28
1704 22 ▶ last if (! (--$cache{'def'}));
Branch: 1 branch
BranchTrueFalseTotal
unless --$cache{"def"} 22 0 22
1705 } else {
1706 6 $cache{'def'}++;
1707 }
1708 }
1709 }
1710 }
1711  
1712 # Process :InitArgs
1713 169 my %pkg_args;
1714 169 my $used_args = {};
1715 169 my $g_args = $GBL{'args'};
1716 169 foreach my $pkg (@{$tree}) {
1717 245 ▶ if (my $spec = $$g_args{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $spec = $g_args->{$pkg}) 105 140 245
1718 105 $pkg_args{$pkg} = _args($pkg, $self, $spec, $all_args, $used_args);
1719 }
1720 }
1721  
1722 # Call :Init subs
1723 156 my $init_subs = $GBL{'sub'}{'init'};
1724 156 foreach my $pkg (@{$tree}) {
1725 232 ▶ if (my $init = $$init_subs{$pkg}) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $init = $init_subs->{$pkg}) { } 27 205 232
elsif (exists $pkg_args{$pkg}) { } 69 136 205
elsif (exists $all_args->{$pkg}) { } 1 135 136
1726 27 local $SIG{'__DIE__'} = 'OIO::trap';
1727 27 ▶ if (exists($pkg_args{$pkg})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pkg_args{$pkg}) { } 23 4 27
1728 23 $self->$init($pkg_args{$pkg});
1729 } else {
1730 4 $self->$init($all_args);
1731 4 undef($used_args);
1732 }
1733  
1734 } elsif (exists($pkg_args{$pkg})) {
1735 69 ▶ if (%{$pkg_args{$pkg}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$pkg_args{$pkg};}) 2 67 69
1736 # It's an error if there are unhandled args, but no :Init sub
1737 OIO::Args::Unhandled->die(
1738 2 'message' => "Unhandled parameter for class '$class': " . join(', ', keys(%{$pkg_args{$pkg}})),
1739 'Usage' => q/Add appropriate 'Field =>' designators to the :InitArgs hash/);
1740 }
1741  
1742 } elsif (exists($$all_args{$pkg})) {
1743 # It's an error if there are unhandled class-specific args
1744 1 ▶ if (ref($$all_args{$pkg}) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $all_args->{$pkg} ne "HASH") 0 1 1
1745 0 OIO::Args->die(
1746 'message' => "Bad class initializer for '$class'",
1747 'Usage' => q/Class initializers must be a hash ref/);
1748 }
1749 OIO::Args::Unhandled->die(
1750 1 'message' => "Unhandled parameter for class '$class': " . join(', ', keys(%{$$all_args{$pkg}})),
1751 'Usage' => q/Add :Init subroutine or :InitArgs hash/);
1752 }
1753 }
1754  
1755 # Any unused args?
1756 151 ▶ if ($used_args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($used_args) 147 4 151
1757 147 my %pkgs;
1758 147 @pkgs{@{$tree}} = undef;
1759 147 foreach my $key (keys(%$all_args)) {
1760 88 ▶ if (exists($pkgs{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pkgs{$key}) { } 9 79 88
1761 9 foreach my $subkey (keys(%{$$all_args{$key}})) {
1762 9 ▶ if (! exists($$used_args{$key}{$subkey})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $used_args->{$key}{$subkey}) 2 7 9
1763 2 OIO::Args::Unhandled->die('message' => "Unhandled parameter for class '$key': $subkey");
1764 }
1765 }
1766 } else {
1767 79 ▶ if (! exists($$used_args{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $used_args->{$key}) 3 76 79
1768 3 OIO::Args::Unhandled->die('message' => "Unhandled parameter: $key");
1769 }
1770 }
1771 }
1772 }
1773  
1774 # Remember object initialization activity caching
1775 146 ▶ if (! $have_cache) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($have_cache) 85 61 146
1776 85 $GBL{'cache'}{$class} = \%cache;
1777 }
1778  
1779 # Done - return object
1780 146 return ($self);
1781 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
1782  
1783  
1784 # Creates a copy of an object
1785 sub clone
1786 {
1787 5 ▶ my ($parent, $is_deep) = @_; # Parent object and deep cloning flag
Subroutine clone: called CC=15 SCAR=31.1
Pod undocumented
1788 5 ▶ $is_deep = ($is_deep) ? 'deep' : ''; # Deep clone the object?
Branch: 1 branch
BranchTrueFalseTotal
$is_deep ? : 3 2 5
1789  
1790 # Must call ->clone() as an object method
1791 5 my $class = Scalar::Util::blessed($parent);
1792 5 ▶ if (! $class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 0 5 5
1793 0 OIO::Method->die('message' => q/'clone' called as a class method/);
1794 }
1795  
1796 # Create a new 'bare' object
1797 5 my $clone = _obj($class);
1798  
1799 # Flag for shared class
1800 5 my $am_sharing = is_sharing($class);
1801  
1802 # Clone the object
1803 5 my $fld_ref = $GBL{'fld'}{'ref'};
1804 5 my $weak = $GBL{'fld'}{'weak'};
1805 5 my $deep = $GBL{'fld'}{'deep'};
1806 5 my $repl = $GBL{'sub'}{'repl'};
1807 5 foreach my $pkg (@{$GBL{'tree'}{'td'}{$class}}) {
1808 # Clone field data from the parent
1809 7 foreach my $fld (@{$$fld_ref{$pkg}}) {
1810 7 ▶ my $fdeep = $is_deep || $$deep{$fld}; # Deep clone the field?
Condition100%3/3
$is_deep || $deep->{$fld}
l!l&&r!l&&!r
412
MC/DC100%2/2
$is_deep || $deep->{$fld}
$is_deep $deep->{$fld}
Truth table100%3/3
A || B
A= $is_deepB= $deep->{$fld}
ABresult
1X1
011
000
1811 7 ▶ lock($fld) if ($am_sharing);
Branch: 1 branch
BranchTrueFalseTotal
if $am_sharing 0 7 7
1812 7 ▶ if (ref($fld) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fld eq 'HASH') { } 0 7 7
1813 $$fld{$$clone} = (! $fdeep) ? $$fld{$$parent}
1814 : ($am_sharing)
1815 ? Object::InsideOut::Util::clone_shared($$fld{$$parent})
1816 0 ▶ : Object::InsideOut::Util::clone($$fld{$$parent});
Branch: 2 branches
BranchTrueFalseTotal
!$fdeep ? : 0 0 0
$am_sharing ? : 0 0 0
1817 0 ▶ if ($$weak{$fld}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($weak->{$fld}) 0 0 0
1818 0 Scalar::Util::weaken($$fld{$$clone});
1819 }
1820 } else {
1821 7 ▶ $$fld[$$clone] = (! $fdeep) ? $$fld[$$parent]
Branch: 2 branches
BranchTrueFalseTotal
!$fdeep ? : 2 5 7
$am_sharing ? : 0 5 5
1822 : ($am_sharing)
1823 ? Object::InsideOut::Util::clone_shared($$fld[$$parent])
1824 : Object::InsideOut::Util::clone($$fld[$$parent]);
1825 7 ▶ if ($$weak{$fld}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($weak->{$fld}) 1 6 7
1826 1 Scalar::Util::weaken($$fld[$$clone]);
1827 }
1828 }
1829 }
1830  
1831 # Dispatch any special replication handling
1832 7 ▶ if (my $replicate = $$repl{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $replicate = $repl->{$pkg}) 0 7 7
1833 0 local $SIG{'__DIE__'} = 'OIO::trap';
1834 0 $parent->$replicate($clone, $is_deep);
1835 }
1836 }
1837  
1838 # Done - return clone
1839 5 return ($clone);
1840 }
1841  
1842  
1843 # Get a metadata object
1844 sub meta
1845 {
1846 2 ▶ my $class = ref($_[0]) || $_[0];
Subroutine meta: called CC=3 SCAR=12.7
Pod documented
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
1847  
1848 # No metadata for OIO
1849 2 ▶ if ($class eq 'Object::InsideOut') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "Object::InsideOut") 0 2 2
1850 0 OIO::Method->die('message' => q/'meta' called on non-class 'Object::InsideOut'/);
1851 }
1852  
1853 2 initialize(); # Perform package initialization, if required
1854  
1855 2 return (Object::InsideOut::Metadata->new('GBL' => \%GBL,
1856 'CLASS' => $class));
1857 }
1858  
1859  
1860 # Put data in a field, making sure that sharing is supported
1861 sub set
1862 {
1863 262 ▶ my ($self, $field, $data) = @_;
Subroutine set: called CC=15 SCAR=35.6
Pod undocumented
1864  
1865 # Must call ->set() as an object method
1866 262 ▶ if (! Scalar::Util::blessed($self)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($self)) 0 262 262
1867 0 OIO::Method->die('message' => q/'set' called as a class method/);
1868 }
1869  
1870 # Restrict usage to inside class hierarchy
1871 262 ▶ if (! $self->isa('Object::InsideOut')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->isa("Object::InsideOut")) 0 262 262
1872 0 my $caller = caller();
1873 0 OIO::Method->die('message' => "Can't call restricted method 'inherit' from class '$caller'");
1874 }
1875  
1876 # Check usage
1877 262 ▶ if (! defined($field)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $field) 0 262 262
1878 0 OIO::Args->die(
1879 'message' => 'Missing field argument',
1880 'Usage' => '$obj->set($field_ref, $data)');
1881 }
1882 262 my $fld_type = ref($field);
1883 262 ▶ if (! $fld_type || ($fld_type ne 'ARRAY' && $fld_type ne 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $fld_type or $fld_type ne "ARRAY" and $fld_type ne "HASH") 0 262 262
Condition50%3/6
not $fld_type or $fld_type ne "ARRAY" and $fld_type ne "HASH"
l!l&&r!l&&!r
00262
$fld_type ne "ARRAY" and $fld_type ne "HASH"
!ll&&!rl&&r
220420
MC/DC0%0/3
not $fld_type or $fld_type ne "ARRAY" and $fld_type ne "HASH"
not $fld_type $fld_type ne "ARRAY" $fld_type ne "HASH"
Truth table50%2/4
not(A) or B and C
A= not $fld_typeB= $fld_type ne "ARRAY"C= $fld_type ne "HASH"
ABCresult
1XX1
0111
00X0
0100
1884 0 OIO::Args->die(
1885 'message' => 'Invalid field argument',
1886 'Usage' => '$obj->set($field_ref, $data)');
1887 }
1888  
1889 # Check data
1890 262 my $weak = $GBL{'fld'}{'weak'}{$field};
1891 262 ▶ if ($weak && ! ref($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($weak and not ref $data) 0 262 262
Condition66%2/3
$weak and not ref $data
!ll&&!rl&&r
25930
MC/DC0%0/2
$weak and not ref $data
$weak not ref $data
Truth table66%2/3
A and not(B)
A= $weakB= not ref $data
ABresult
0X0
100
111
1892 0 OIO::Args->die(
1893 'message' => "Bad argument: $data",
1894 'Usage' => q/Argument to specified field must be a reference/);
1895 }
1896  
1897 # Handle sharing
1898 262 ▶ if ($GBL{'share'}{'ok'} && threads::shared::is_shared($field)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($GBL{'share'}{'ok'} and threads::shared::is_shared($field)) { } 0 262 262
Condition33%1/3
$GBL{"share"}{"ok"} and threads::shared::is_shared($field)
!ll&&!rl&&r
26200
MC/DC0%0/2
$GBL{"share"}{"ok"} and threads::shared::is_shared($field)
$GBL{"share"}{"ok"} threads::shared::is_shared($field)
Truth table33%1/3
A and B
A= $GBL{"share"}{"ok"}B= threads::shared::is_shared($field)
ABresult
0X0
100
111
1899 0 lock($field);
1900 0 ▶ if ($fld_type eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fld_type eq 'HASH') { } 0 0 0
1901 0 $$field{$$self} = make_shared($data);
1902 } else {
1903 0 $$field[$$self] = make_shared($data);
1904 }
1905  
1906 } else {
1907 # No sharing - just store the data
1908 262 ▶ if ($fld_type eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fld_type eq 'HASH') { } 42 220 262
1909 42 $$field{$$self} = $data;
1910 } else {
1911 220 $$field[$$self] = $data;
1912 }
1913 }
1914  
1915 # Weaken data, if required
1916 262 ▶ if ($weak) {
Branch: 1 branch
BranchTrueFalseTotal
if ($weak) 3 259 262
1917 3 ▶ if ($fld_type eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fld_type eq 'HASH') { } 0 3 3
1918 0 Scalar::Util::weaken($$field{$$self});
1919 } else {
1920 3 Scalar::Util::weaken($$field[$$self]);
1921 }
1922 }
1923 }
1924  
1925  
1926 # Object Destructor
1927 sub DESTROY
1928 {
1929 196 ▶ my $self = shift;
Subroutine DESTROY: called CC=32 SCAR=51.1
1930 196 my $class = ref($self);
1931  
1932 196 ▶ return if (! $$self);
Branch: 1 branch
BranchTrueFalseTotal
unless $$self 18 178 196
1933  
1934 # Grab any error coming into this routine
1935 178 my $err = $@;
1936  
1937 # Preserve other error variables
1938 178 local($!, $^E, $?);
1939  
1940 # Workaround for Perl's "in cleanup" bug
1941 178 ▶ if ($threads::shared::threads_shared && ! $GBL{'term'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($threads::shared::threads_shared and not $GBL{"term"}) 0 178 178
Condition33%1/3
$threads::shared::threads_shared and not $GBL{"term"}
!ll&&!rl&&r
17800
MC/DC0%0/2
$threads::shared::threads_shared and not $GBL{"term"}
$threads::shared::threads_shared not $GBL{"term"}
Truth table33%1/3
A and not(B)
A= $threads::shared::threads_sharedB= not $GBL{"term"}
ABresult
0X0
100
111
1942 0 eval {
1943 0 my $bug = keys(%{$GBL{'id'}{'obj'}})
1944 0 ▶ + keys(%{$GBL{'id'}{'reuse'}})
Branch: 1 branch
BranchTrueFalseTotal
exists $GBL{'share'}{'obj'} ? : 0 0 0
1945 + ((exists($GBL{'share'}{'obj'}))
1946 0 ? keys(%{$GBL{'share'}{'obj'}})
1947 : 0);
1948 };
1949 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1950 0 $GBL{'term'} = 1;
1951 }
1952 }
1953  
1954 178 eval {
1955 178 my $is_sharing = is_sharing($class);
1956 178 ▶ if ($is_sharing) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_sharing) { } 0 178 178
elsif ($threads::threads) { } 0 178 178
1957 # Thread-shared object
1958 0 my $tid = $GBL{'tid'};
1959  
1960 0 ▶ if ($GBL{'term'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($GBL{'term'}) { } 0 0 0
elsif (exists $GBL{'share'}{'obj'}) { } 0 0 0
1961 0 ▶ return if ($tid); # Continue only if main thread
Branch: 1 branch
BranchTrueFalseTotal
if $tid 0 0 0
1962  
1963 } elsif (exists($GBL{'share'}{'obj'})) {
1964 0 my $so_cl = $GBL{'share'}{'obj'}{$class};
1965 0 ▶ if (! exists($$so_cl{$$self})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$so_cl{$$self}) 0 0 0
1966 # This can happen when a non-shared object
1967 # is returned from a thread
1968 0 warn("ERROR: Attempt to DESTROY object ID $$self of class $class in thread ID $tid twice\n");
1969 0 return;
1970 }
1971  
1972 # Remove thread ID from this object's thread tracking list
1973 # NOTE: The threads->object() test was added for the case
1974 # where OIO objects are passed via Thead::Queue. I don't
1975 # know if this will cause problems with detached threads as
1976 # threads->object() returns undef for them. Also, the main
1977 # thread (0) is always a valid thread.
1978 0 lock($so_cl);
1979 0 ▶ if (@{$$so_cl{$$self}} = grep { ($_ != $tid) &&
Branch: 2 branches
BranchTrueFalseTotal
if (@{$$so_cl{$$self};} = grep({$_ != $tid and $_ == 0 || "threads"->object($_);} @{$$so_cl{$$self};})) 0 0 0
$_ != $tid and $_ == 0 || "threads"->object($_) 0 0 0
Condition0%0/6
$_ != $tid && ($_ == 0 || 'threads'->object($_))
!ll&&!rl&&r
000
$_ == 0 or "threads"->object($_)
l!l&&r!l&&!r
000
MC/DC0%0/3
$_ != $tid && ($_ == 0 || 'threads'->object($_))
$_ != $tid $_ == 0 "threads"->object($_)
Truth table0%0/4
A && B or C
A= $_ != $tidB= $_ == 0C= "threads"->object($_)
ABCresult
0XX0
1000
11X1
1011
1980 (($_ == 0) || threads->object($_)) }
1981 0 @{$$so_cl{$$self}}) {
1982 0 return;
1983 }
1984  
1985 # Delete the object from the thread tracking registry
1986 0 delete($$so_cl{$$self});
1987 }
1988  
1989 } elsif ($threads::threads) {
1990 0 my $obj_cl = $GBL{'obj'}{$class};
1991 0 ▶ if (! exists($$obj_cl{$$self})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$obj_cl{$$self}) 0 0 0
1992 0 warn("ERROR: Attempt to DESTROY object ID $$self of class $class twice\n");
1993 0 return;
1994 }
1995  
1996 # Delete this non-thread-shared object from the thread cloning
1997 # registry
1998 0 delete($$obj_cl{$$self});
1999 }
2000  
2001 # Dispatch any special destruction handling
2002 178 my $dest_err;
2003 178 my $dest_subs = $GBL{'sub'}{'dest'};
2004 178 my $fld_refs = $GBL{'fld'}{'ref'};
2005 178 foreach my $pkg (@{$GBL{'tree'}{'bu'}{$class}}) {
2006 266 ▶ if (my $destroy = $$dest_subs{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $destroy = $dest_subs->{$pkg}) 6 260 266
2007 6 eval {
2008 6 local $SIG{'__DIE__'} = 'OIO::trap';
2009 6 $self->$destroy();
2010 };
2011 6 $dest_err = OIO::combine($dest_err, $@);
2012 }
2013 }
2014  
2015 # Delete object field data
2016 178 foreach my $pkg (@{$GBL{'tree'}{'bu'}{$class}}) {
2017 266 foreach my $fld (@{$$fld_refs{$pkg}}) {
2018 # If sharing, then must lock object field
2019 535 ▶ lock($fld) if ($is_sharing);
Branch: 1 branch
BranchTrueFalseTotal
if $is_sharing 0 535 535
2020 535 ▶ if (ref($fld) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fld eq 'HASH') { } 60 475 535
2021 60 ▶ if ($is_sharing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_sharing) 0 60 60
2022 # Workaround for Perl's "in cleanup" bug
2023 0 ▶ next if ! defined($$fld{$$self});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$fld{$$self} 0 0 0
2024 }
2025 60 delete($$fld{$$self});
2026 } else {
2027 475 ▶ if ($is_sharing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_sharing) 0 475 475
2028 # Workaround for Perl's "in cleanup" bug
2029 0 ▶ next if ! defined($$fld[$$self]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$fld[$$self] 0 0 0
2030 }
2031 475 undef($$fld[$$self]);
2032 }
2033 }
2034 }
2035  
2036 # Unlock the object
2037 178 ▶ Internals::SvREADONLY($$self, 0) if ($] >= 5.008003);
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.008003" 178 0 178
2038  
2039 # Reclaim the object ID if applicable
2040 178 ▶ if ($GBL{'sub'}{'id'}{$class}{'code'} == \&_ID) {
Branch: 1 branch
BranchTrueFalseTotal
if ($GBL{"sub"}{"id"}{$class}{"code"} == \&Object::InsideOut::_ID) 169 9 178
2041 169 _ID($class, $$self);
2042 }
2043  
2044 # Erase the object ID - just in case
2045 178 $$self = undef;
2046  
2047 # Propagate any errors
2048 178 ▶ if ($dest_err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dest_err) 3 175 178
2049 3 die($dest_err);
2050 }
2051 };
2052  
2053 # Propagate any errors
2054 178 ▶ if ($err || $@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err or $@) 43 135 178
Condition100%3/3
$err or $@
l!l&&r!l&&!r
421135
MC/DC100%2/2
$err or $@
$err $@
Truth table100%3/3
A or B
A= $errB= $@
ABresult
1X1
011
000
2055 43 $@ = OIO::combine($err, $@);
2056 43 ▶ die("$@") if (! $err);
Branch: 1 branch
BranchTrueFalseTotal
if not $err 1 42 43
2057 }
2058 }
2059  
2060  
2061 # OIO specific ->can()
2062 sub can :Method(Object)
2063 {
2064 71 ▶ my ($thing, $method) = @_;
Subroutine can: called CC=5 SCAR=19.6
Pod documented
2065  
2066 71 ▶ return if (! defined($thing));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 0 71 71
2067  
2068 # Metadata call for methods
2069 71 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 71 71
2070 0 my $meths = Object::InsideOut::meta($thing)->get_methods();
2071 0 ▶ return (wantarray()) ? (keys(%$meths)) : [ keys(%$meths) ];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2072 }
2073  
2074 71 ▶ return if (! defined($method));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $method 0 71 71
2075  
2076 # Try UNIVERSAL::can()
2077 71 eval { $thing->Object::InsideOut::SUPER::can($method) };
2078 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2079  
2080  
2081 # OIO specific ->isa()
2082 sub isa :Method(Object)
2083 {
2084 654 ▶ my ($thing, $type) = @_;
Subroutine isa: called CC=4 SCAR=15.0
Pod documented
2085  
2086 654 ▶ return ('') if (! defined($thing));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 0 654 654
2087  
2088 # Metadata call for classes
2089 654 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 654 654
2090 0 return Object::InsideOut::meta($thing)->get_classes();
2091 }
2092  
2093 # Workaround for Perl bug #47233
2094 654 ▶ return ('') if (! defined($type));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 654 654
2095  
2096 # Try UNIVERSAL::isa()
2097 654 eval { $thing->Object::InsideOut::SUPER::isa($type); }
2098 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2099  
2100  
2101 ### Serialization Support Using Storable ###
2102  
2103 sub STORABLE_freeze :Sub
2104 {
2105 5 ▶ my ($self, $cloning) = @_;
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
2106 5 return ('', $self->dump());
2107 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2108  
2109 sub STORABLE_thaw :Sub
2110 {
2111 5 ▶ my ($obj, $cloning, $data);
Subroutine STORABLE_thaw: called CC=5 SCAR=16.5
Pod undocumented
2112 5 ▶ if (@_ == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 4) { } 5 0 5
2113 5 ($obj, $cloning, undef, $data) = @_;
2114 } else {
2115 # Backward compatibility
2116 0 ($obj, $cloning, $data) = @_;
2117 }
2118  
2119 # Recreate the object
2120 5 my $self;
2121 5 eval {
2122 5 $self = Object::InsideOut->pump($data);
2123 };
2124 5 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 4 5
2125 1 die($@->as_string()); # Storable doesn't like exception objects
2126 }
2127  
2128 # Transfer the ID to Storable's object
2129 4 $$obj = $$self;
2130 # Make object shared, if applicable
2131 4 ▶ if (is_sharing(ref($obj))) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_sharing(ref $obj)) 0 4 4
2132 0 threads::shared::share($obj);
2133 }
2134 # Make object readonly
2135 4 ▶ if ($] >= 5.008003) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.008003") 4 0 4
2136 4 Internals::SvREADONLY($$obj, 1);
2137 4 Internals::SvREADONLY($$self, 0);
2138 }
2139 # Prevent object destruction
2140 4 undef($$self);
2141 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2142  
2143  
2144 ### Accessor Generator ###
2145  
2146 # Names a field for dumping
2147 sub add_dump_field :Sub(Private)
2148 {
2149 163 ▶ my ($src, $name, $fld, $dump) = @_;
Subroutine add_dump_field: called CC=11 SCAR=30.0
Pod undocumented
2150  
2151 # Name already in use for different field
2152 163 ▶ if (exists($$dump{$name}) && ($fld != $$dump{$name}{'fld'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dump->{$name} and $fld != $dump->{$name}{"fld"}) 0 163 163
Condition66%2/3
exists $dump->{$name} and $fld != $dump->{$name}{"fld"}
!ll&&!rl&&r
15940
MC/DC0%0/2
exists $dump->{$name} and $fld != $dump->{$name}{"fld"}
exists $dump->{$name} $fld != $dump->{$name}{"fld"}
Truth table66%2/3
A and B
A= exists $dump->{$name}B= $fld != $dump->{$name}{"fld"}
ABresult
0X0
100
111
2153 0 return ('conflict');
2154 }
2155  
2156 # Entry already exists for field
2157 163 ▶ if (my ($old_name) = grep { $$dump{$_}{'fld'} == $fld } keys(%$dump)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($old_name) = grep({$dump->{$_}{"fld"} == $fld;} keys %$dump)) 20 143 163
2158 20 my $old_src = $$dump{$old_name}{'src'};
2159 20 ▶ if ($old_src eq 'Name') {
Branch: 7 branches
BranchTrueFalseTotal
if ($old_src eq 'Name') { } 7 13 20
elsif ($src eq 'Name') { } 11 2 13
elsif ($old_src eq 'InitArgs') { } 0 2 2
elsif ($src eq 'InitArgs') { } 2 0 2
elsif ($old_src eq 'Get') { } 0 0 0
elsif ($src eq 'Get') { } 0 0 0
elsif ($old_src eq 'Set') { } 0 0 0
2160 7 return ('named');
2161 } elsif ($src eq 'Name') {
2162 11 delete($$dump{$old_name});
2163 } elsif ($old_src eq 'InitArgs') {
2164 0 return ('named');
2165 } elsif ($src eq 'InitArgs') {
2166 2 delete($$dump{$old_name});
2167 } elsif ($old_src eq 'Get') {
2168 0 return ('named');
2169 } elsif ($src eq 'Get') {
2170 0 delete($$dump{$old_name});
2171 } elsif ($old_src eq 'Set') {
2172 0 return ('named');
2173 } else {
2174 0 delete($$dump{$old_name}); # Shouldn't get here
2175 }
2176 }
2177  
2178 156 $$dump{$name} = { fld => $fld, src => $src };
2179 156 return ('okay');
2180 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2181  
2182  
2183 # Utility sub to infer class API from symbol table...
2184 # (replaces ->meta->get_methods for non-OIO classes)
2185 sub get_symtab_methods_for :Sub(Private)
2186 {
2187 1 ▶ my ($class_delegated_to) = @_;
Subroutine get_symtab_methods_for: called CC=4 SCAR=13.9
Pod undocumented
2188  
2189 1 my %methods; #...collects the methods that are found
2190  
2191 # Walk the class's inheritance tree...
2192 1 my @hierarchy = ($class_delegated_to);
2193 1 ▶ while (my $classname = shift @hierarchy) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $classname = shift @hierarchy) 4 1 5
2194 44 ▶ no strict 'refs'; #...because symbols are inherently symbolic
Subroutine BEGIN: called CC=1 SCAR=0.0
2195  
2196 # Accumulate ancestors for subsequent investigation...
2197 4 push(@hierarchy, @{$classname.'::ISA'});
2198  
2199 # Grab and remember all subs from this class's symbol table...
2200 4 for my $symname (keys(%{$classname.'::'})) {
2201 # Only want symbols that define subroutines...
2202 18 ▶ next if !*{$classname.'::'.$symname}{CODE};
Branch: 1 branch
BranchTrueFalseTotal
unless *{$classname . '::' . $symname;}{"CODE"} 11 7 18
2203 # Save the necessary info...
2204 7 $methods{$symname}{'class'} = $class_delegated_to;
2205 }
2206 }
2207  
2208 1 return \%methods
2209 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2210  
2211  
2212 # Utility sub to handle :Handles(Class::*) feature...
2213 sub get_class_methods :Sub(Private)
2214 {
2215 8 ▶ my ($class_delegated_from, $class_delegated_to) = @_;
Subroutine get_class_methods: called CC=5 SCAR=16.1
Pod undocumented
2216  
2217 # Not expandable...
2218 8 ▶ return $class_delegated_to if $class_delegated_to !~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $class_delegated_to =~ /::/ 5 3 8
2219  
2220 # Clean up any trailing ::...
2221 3 $class_delegated_to =~ s/::+$//;
2222  
2223 # Grab all known method names of specified class...
2224 3 ▶ my $methods = $class_delegated_to->can('meta')
Branch: 1 branch
BranchTrueFalseTotal
$class_delegated_to->can('meta') ? : 2 1 3
2225 ? $class_delegated_to->meta()->get_methods()
2226 : get_symtab_methods_for($class_delegated_to);
2227  
2228 # Select the "real" ones...
2229 44 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2230 return grep {
2231 # Ignore "infrastructure" methods...
2232 !/^(?:new|clone|meta|set)$/
2233  
2234 # Ignore Object::InsideOut internal methods...
2235 && $methods->{$_}{class} eq $class_delegated_to
2236  
2237 # Ignore methods already installed...
2238 13 && !*{"${class_delegated_from}::$_"}{CODE}
2239  
2240 3 ▶ } keys %{$methods};
Branch: 1 branch
BranchTrueFalseTotal
not /^(?:new|clone|meta|set)$/ and $methods->{$_}{"class"} eq $class_delegated_to and not *{"${class_delegated_from}::$_";}{"CODE"} 13 27 40
Condition100%3/3
not /^(?:new|clone|meta|set)$/ and $methods->{$_}{"class"} eq $class_delegated_to
!ll&&!rl&&r
91813
MC/DC100%2/2
not /^(?:new|clone|meta|set)$/ and $methods->{$_}{"class"} eq $class_delegated_to
not /^(?:new|clone|meta|set)$/ $methods->{$_}{"class"} eq $class_delegated_to
Truth table100%3/3
not(A) and B
A= not /^(?:new|clone|meta|set)$/B= $methods->{$_}{"class"} eq $class_delegated_to
ABresult
0X0
100
111
2241 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2242  
2243  
2244 # Creates object data accessors for classes
2245 sub create_accessors :Sub(Private)
2246 {
2247 269 ▶ my ($pkg, $field_ref, $attr, $use_want) = @_;
Subroutine create_accessors: called CC=152 SCAR=59.5
Pod undocumented
2248  
2249 # Extract info from attribute
2250 269 my ($kind) = $attr =~ /^(\w+)/;
2251 269 my ($name) = $attr =~ /^\w+\s*\(\s*'?([\w:()]*)'?\s*\)$/;
2252 269 my ($decl) = $attr =~ /^\w+\s*\(\s*(.*)\s*\)/;
2253 269 my $type_code;
2254  
2255 269 ▶ if ($name) {
Branch: 5 branches
BranchTrueFalseTotal
if ($name) { } 92 177 269
elsif (not $decl) { } 96 81 177
elsif ($kind =~ /^Type/i and $decl =~ /^(?:sub|\\&)/) { } 3 78 81
elsif ($kind =~ /^Hand/i) { } 2 76 78
elsif (not $kind =~ /^Field/i) { } 10 66 76
2256 92 $decl = "{'$kind'=>'$name'}";
2257 92 undef($name);
2258 } elsif (! $decl) {
2259 96 ▶ return if ($kind =~ /^Field/i);
Branch: 1 branch
BranchTrueFalseTotal
if $kind =~ /^Field/i 96 0 96
2260 0 OIO::Attribute->die(
2261 'message' => "Missing declarations for attribute in package '$pkg'",
2262 'Attribute' => $attr);
2263 ▶ } elsif (($kind =~ /^Type/i) && ($decl =~ /^(?:sub|\\&)/)) {
Condition100%3/3
$kind =~ /^Type/i and $decl =~ /^(?:sub|\\&)/
!ll&&!rl&&r
7623
MC/DC100%2/2
$kind =~ /^Type/i and $decl =~ /^(?:sub|\\&)/
$kind =~ /^Type/i $decl =~ /^(?:sub|\\&)/
Truth table100%3/3
A and B
A= $kind =~ /^Type/iB= $decl =~ /^(?:sub|\\&)/
ABresult
0X0
100
111
2264 3 $type_code = $decl;
2265 3 $decl = "{'$kind'=>$decl}";
2266 } elsif ($kind =~ /^Hand/i) {
2267 2 $decl =~ s/['",]/ /g;
2268 2 $decl = "{'$kind'=>'$decl'}";
2269 } elsif ($kind !~ /^Field/i) {
2270 10 ▶ if (! ($decl =~ s/'?name'?\s*=>/'$kind'=>/i)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($decl =~ s/'?name'?\s*=>/'${kind}'=>/i) 0 10 10
2271 0 OIO::Attribute->die(
2272 'message' => "Missing 'Name' parameter for attribute in package '$pkg'",
2273 'Attribute' => $attr);
2274 }
2275 }
2276  
2277 # Parse the accessor declaration
2278 173 my $acc_spec;
2279 {
2280 # Ensure the attribute declaration is a hash
2281 173 ▶ if ($decl !~ /^{/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($decl =~ /^{/) 60 113 173
2282 60 $decl = "{ $decl }";
2283 }
2284  
2285 173 my @errs;
2286 173 ▶ local $SIG{'__WARN__'} = sub { push(@errs, @_); };
Subroutine __ANON__: not called CC=1 SCAR=1.2
2287  
2288 173 ▶ eval "package $pkg; use $]; \$acc_spec = $decl";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2289  
2290 173 ▶ if ($@ || @errs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or @errs) 0 173 173
Condition33%1/3
$@ or @errs
l!l&&r!l&&!r
00173
MC/DC0%0/2
$@ or @errs
$@ @errs
Truth table33%1/3
A or B
A= $@B= @errs
ABresult
1X1
011
000
2291 0 ▶ my ($err) = split(/ at /, $@ || join(" | ", @errs));
Condition0%0/3
$@ || join(' | ', @errs)
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || join(' | ', @errs)
$@ join(' | ', @errs)
Truth table0%0/3
A || B
A= $@B= join(' | ', @errs)
ABresult
1X1
011
000
2292 0 OIO::Attribute->die(
2293 'message' => "Malformed attribute in package '$pkg'",
2294 'Error' => $err,
2295 'Attribute' => $attr);
2296 }
2297 }
2298  
2299 173 my $fld_type = $GBL{'fld'}{'type'};
2300  
2301 # Get info for accessors/delegators
2302 173 my ($get, $set, $return, $private, $restricted, $lvalue, $arg, $pre, $delegate);
2303 173 my $accessor_type = 'accessor';
2304 173 ▶ if ($kind !~ /^arg$/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($kind =~ /^arg$/i) 152 21 173
2305 152 foreach my $key (keys(%{$acc_spec})) {
2306 213 my $key_uc = uc($key);
2307 213 my $val = $$acc_spec{$key};
2308  
2309 # :InitArgs
2310 213 ▶ if ($key_uc =~ /ALL/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($key_uc =~ /ALL/) { } 14 199 213
elsif ($key_uc =~ /R(?:EAD)?O(?:NLY)?/) { } 4 195 199
elsif ($key_uc =~ /ARG/) { } 2 193 195
2311 14 $arg = $val;
2312 14 ▶ if ($key_uc eq 'ALL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key_uc eq "ALL") 14 0 14
2313 14 $key_uc = 'ACC';
2314 }
2315 } elsif ($key_uc =~ /R(?:EAD)?O(?:NLY)?/) {
2316 4 $arg = $val;
2317 4 ▶ if ($key_uc =~ /^R(?:EAD)?O(?:NLY)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key_uc =~ /^R(?:EAD)?O(?:NLY)?$/) 3 1 4
2318 3 $key_uc = 'GET';
2319 }
2320 } elsif ($key_uc =~ /ARG/) {
2321 2 $arg = $val;
2322 2 $key_uc = 'IGNORE';
2323 }
2324  
2325 # Standard accessors
2326 213 ▶ if ($key_uc =~ /^ST.*D.*R(?:EAD)?O(?:NLY)?/) {
Branch: 14 branches
BranchTrueFalseTotal
if ($key_uc =~ /^ST.*D.*R(?:EAD)?O(?:NLY)?/) { } 1 212 213
elsif ($key_uc =~ /^ST.*D/) { } 15 197 212
elsif ($key_uc =~ /^ACC|^COM|^MUT|[GS]ET/) { } 118 79 197
elsif ($key_uc eq 'COPY' or $key_uc eq 'CLONE') { } 0 79 79
elsif ($key_uc eq 'DEEP') { } 0 79 79
elsif ($key_uc =~ /^WEAK/) { } 0 79 79
elsif ($key_uc eq 'TYPE') { } 49 30 79
elsif ($key_uc eq 'NAME') { } 3 27 30
elsif ($key_uc =~ /^RET(?:URN)?$/) { } 15 12 27
elsif ($key_uc =~ /^PERM|^PRIV|^REST/) { } 3 9 12
elsif ($key_uc =~ /^LV/) { } 0 9 9
elsif ($key_uc =~ /^PRE/) { } 0 9 9
elsif ($key_uc =~ /^HAND/) { } 7 2 9
elsif ($key_uc ne 'IGNORE') { } 0 2 2
2327 1 $get = 'get_' . $val;
2328 }
2329 elsif ($key_uc =~ /^ST.*D/) {
2330 15 $get = 'get_' . $val;
2331 15 $set = 'set_' . $val;
2332 }
2333 # Get and/or set accessors
2334 elsif ($key_uc =~ /^ACC|^COM|^MUT|[GS]ET/) {
2335 # Get accessor
2336 118 ▶ if ($key_uc =~ /ACC|COM|MUT|GET/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key_uc =~ /ACC|COM|MUT|GET/) 110 8 118
2337 110 $get = $val;
2338 }
2339 # Set accessor
2340 118 ▶ if ($key_uc =~ /ACC|COM|MUT|SET/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key_uc =~ /ACC|COM|MUT|SET/) 78 40 118
2341 78 $set = $val;
2342 }
2343 }
2344 # Deep clone the field
2345 ▶ elsif ($key_uc eq 'COPY' || $key_uc eq 'CLONE') {
Condition33%1/3
$key_uc eq "COPY" or $key_uc eq "CLONE"
l!l&&r!l&&!r
0079
MC/DC0%0/2
$key_uc eq "COPY" or $key_uc eq "CLONE"
$key_uc eq "COPY" $key_uc eq "CLONE"
Truth table33%1/3
A or B
A= $key_uc eq "COPY"B= $key_uc eq "CLONE"
ABresult
1X1
011
000
2346 0 ▶ if (uc($val) eq 'DEEP') {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $val eq "DEEP") 0 0 0
2347 0 $GBL{'fld'}{'deep'}{$field_ref} = 1;
2348 }
2349 0 next;
2350 } elsif ($key_uc eq 'DEEP') {
2351 0 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 0 0 0
2352 0 $GBL{'fld'}{'deep'}{$field_ref} = 1;
2353 }
2354 0 next;
2355 }
2356 # Store weakened refs
2357 elsif ($key_uc =~ /^WEAK/) {
2358 0 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 0 0 0
2359 0 $GBL{'fld'}{'weak'}{$field_ref} = 1;
2360 }
2361 0 next;
2362 }
2363 # Field type checking for set accessor
2364 elsif ($key_uc eq 'TYPE') {
2365 # Check type-checking setting and set default
2366 49 ▶ if (!$val || (ref($val) && (ref($val) ne 'CODE'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $val or ref $val and ref $val ne "CODE") 0 49 49
Condition50%3/6
not $val or ref $val and ref $val ne "CODE"
l!l&&r!l&&!r
0049
ref $val and ref $val ne "CODE"
!ll&&!rl&&r
4180
MC/DC0%0/3
not $val or ref $val and ref $val ne "CODE"
not $val ref $val ref $val ne "CODE"
Truth table25%1/4
not(A) or B and C
A= not $valB= ref $valC= ref $val ne "CODE"
ABCresult
1XX1
0111
00X0
0100
2367 0 OIO::Attribute->die(
2368 'message' => "Can't create accessor method for package '$pkg'",
2369 'Info' => q/Bad 'Type' specifier: Must be a 'string' or code ref/,
2370 'Attribute' => $attr);
2371 }
2372 # Normalize type declaration
2373 49 ▶ if (! ref($val)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $val) 41 8 49
2374 41 $val =~ s/\s//g;
2375 41 my $subtype;
2376 41 ▶ if ($val =~ /^(.*)\((.+)\)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^(.*)\((.+)\)$/i) 3 38 41
2377 3 $val = $1;
2378 3 $subtype = $2;
2379 3 ▶ if ($subtype =~ /^num(?:ber|eric)?$/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($subtype =~ /^num(?:ber|eric)?$/i) { } 2 1 3
elsif ($subtype =~ /^scalar$/i) { } 0 1 1
2380 2 $subtype = 'numeric';
2381 } elsif ($subtype =~ /^scalar$/i) {
2382 0 $subtype = 'scalar';
2383 }
2384 }
2385 41 ▶ if ($val =~ /^num(?:ber|eric)?$/i) {
Branch: 5 branches
BranchTrueFalseTotal
if ($val =~ /^num(?:ber|eric)?$/i) { } 11 30 41
elsif ($val =~ /^scalar$/i) { } 1 29 30
elsif ($val =~ /^(?:list|array)$/i) { } 9 20 29
elsif (uc $val eq 'HASH') { } 4 16 20
elsif ($val =~ /^(hash|array|scalar)_?ref$/i) { } 7 9 16
2386 11 $val = 'numeric';
2387 } elsif ($val =~ /^scalar$/i) {
2388 1 $val = 'scalar';
2389 } elsif ($val =~ /^(?:list|array)$/i) {
2390 9 $val = 'list';
2391 } elsif (uc($val) eq 'HASH') {
2392 4 $val = 'HASH';
2393 } elsif ($val =~ /^(hash|array|scalar)_?ref$/i) {
2394 7 $val = uc($1) . '_ref';
2395 }
2396 41 ▶ if ($subtype) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subtype) 3 38 41
2397 3 $val .= "($subtype)";
2398 }
2399 }
2400 49 my $type = {
2401 type => $val,
2402 code => $type_code,
2403 };
2404 49 $$fld_type{$field_ref} = $type;
2405 49 push(@{$GBL{'fld'}{'regen'}{'type'}}, [ $field_ref, $type ]);
2406 49 next;
2407 }
2408 # Field name for ->dump()
2409 elsif ($key_uc eq 'NAME') {
2410 3 $name = $val;
2411 }
2412 # Set accessor return type
2413 elsif ($key_uc =~ /^RET(?:URN)?$/) {
2414 15 $return = uc($val);
2415 }
2416 # Set accessor permission
2417 elsif ($key_uc =~ /^PERM|^PRIV|^REST/) {
2418 3 ▶ if ($key_uc =~ /^PERM/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($key_uc =~ /^PERM/) { } 3 0 3
elsif ($key_uc =~ /^PRIV/) { } 0 0 0
elsif ($key_uc =~ /^REST/) { } 0 0 0
2419 3 ▶ if ($val =~ /^PRIV/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^PRIV/i) { } 1 2 3
elsif ($val =~ /^REST/i) { } 2 0 2
2420 1 my @exempt = split(/[(),\s]+/, $val);
2421 1 @exempt = grep { $_ } @exempt;
2422 1 shift(@exempt);
2423 1 unshift(@exempt, $pkg);
2424 1 $private = "'" . join("','", @exempt) . "'";
2425 } elsif ($val =~ /^REST/i) {
2426 2 my @exempt = split(/[(),\s]+/, $val);
2427 2 @exempt = grep { $_ } @exempt;
2428 2 shift(@exempt);
2429 2 $restricted = "'" . join("','", @exempt) . "'";
2430 }
2431 } elsif ($key_uc =~ /^PRIV/) {
2432 0 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 0 0 0
2433 0 $private = "'$pkg'";
2434 }
2435 } elsif ($key_uc =~ /^REST/) {
2436 0 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 0 0 0
2437 0 $restricted = '';
2438 }
2439 }
2440 }
2441 # :lvalue accessor
2442 elsif ($key_uc =~ /^LV/) {
2443 0 ▶ if ($val && !Scalar::Util::looks_like_number($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val and not &Scalar::Util::looks_like_number($val)) { } 0 0 0
Condition0%0/3
$val and not &Scalar::Util::looks_like_number($val)
!ll&&!rl&&r
000
MC/DC0%0/2
$val and not &Scalar::Util::looks_like_number($val)
$val not &Scalar::Util::looks_like_number($val)
Truth table0%0/3
A and not(B)
A= $valB= not &Scalar::Util::looks_like_number($val)
ABresult
0X0
100
111
2444 0 $get = $val;
2445 0 $set = $val;
2446 0 $lvalue = 1;
2447 } else {
2448 0 $lvalue = $val;
2449 }
2450 }
2451 # Preprocessor
2452 elsif ($key_uc =~ /^PRE/) {
2453 0 $pre = $val;
2454 0 ▶ if (ref($pre) ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pre ne "CODE") 0 0 0
2455 0 OIO::Attribute->die(
2456 'message' => "Can't create accessor method for package '$pkg'",
2457 'Info' => q/Bad 'Preprocessor' specifier: Must be a code ref/,
2458 'Attribute' => $attr);
2459 }
2460 }
2461 # Delegator
2462 elsif ($key_uc =~ /^HAND/) {
2463 7 $delegate = $val;
2464 7 $accessor_type = 'delegator';
2465 }
2466 # Unknown parameter
2467 elsif ($key_uc ne 'IGNORE') {
2468 0 OIO::Attribute->die(
2469 'message' => "Can't create accessor method for package '$pkg'",
2470 'Info' => "Unknown accessor specifier: $key");
2471 }
2472  
2473 # $val must have a usable value
2474 164 ▶ if (! defined($val) || $val eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or $val eq "") 0 164 164
Condition33%1/3
not defined $val or $val eq ""
l!l&&r!l&&!r
00164
MC/DC0%0/2
not defined $val or $val eq ""
not defined $val $val eq ""
Truth table33%1/3
not(A) or B
A= not defined $valB= $val eq ""
ABresult
1X1
011
000
2475 0 OIO::Attribute->die(
2476 'message' => "Invalid '$key' entry in attribute",
2477 'Attribute' => $attr);
2478 }
2479 }
2480 }
2481  
2482 # :InitArgs
2483 173 ▶ if ($arg || ($kind =~ /^ARG$/i)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg or $kind =~ /^ARG$/i) 41 132 173
Condition100%3/3
$arg or $kind =~ /^ARG$/i
l!l&&r!l&&!r
2021132
MC/DC100%2/2
$arg or $kind =~ /^ARG$/i
$arg $kind =~ /^ARG$/i
Truth table100%3/3
A or B
A= $argB= $kind =~ /^ARG$/i
ABresult
1X1
011
000
2484 41 my $g_args = $GBL{'args'};
2485 41 ▶ if (! exists($$g_args{$pkg})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $g_args->{$pkg}) 18 23 41
2486 18 $$g_args{$pkg} = {};
2487 }
2488 41 $g_args = $$g_args{$pkg};
2489 41 ▶ if (!$arg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg) 21 20 41
2490 21 $arg = hash_re($acc_spec, qr/^ARG$/i);
2491 21 $$g_args{$arg} = normalize($acc_spec);
2492 }
2493 41 ▶ if (!defined($name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 41 0 41
2494 41 $name = $arg;
2495 }
2496 41 $$g_args{$arg}{'_F'} = $field_ref;
2497 # Add type to :InitArgs
2498 41 ▶ if ($$fld_type{$field_ref} && ! exists($$g_args{$arg}{'_T'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fld_type->{$field_ref} and not exists $g_args->{$arg}{"_T"}) 11 30 41
Condition66%2/3
$fld_type->{$field_ref} and not exists $g_args->{$arg}{"_T"}
!ll&&!rl&&r
30011
MC/DC50%1/2
$fld_type->{$field_ref} and not exists $g_args->{$arg}{"_T"}
$fld_type->{$field_ref} not exists $g_args->{$arg}{"_T"}
Truth table66%2/3
A and not(B)
A= $fld_type->{$field_ref}B= not exists $g_args->{$arg}{"_T"}
ABresult
0X0
100
111
2499 11 $$g_args{$arg}{'_T'} = $$fld_type{$field_ref}{'type'};
2500 }
2501  
2502 # Add default to :InitArgs
2503 41 ▶ if (my $g_def = delete($GBL{'fld'}{'def'}{$pkg})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $g_def = delete $GBL{"fld"}{"def"}{$pkg}) 23 18 41
2504 23 my @defs;
2505 23 foreach my $item (@{$g_def}) {
2506 100 ▶ if ($field_ref == $$item[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field_ref == $item->[0]) { } 8 92 100
2507 8 $$g_args{$arg}{'_D'} = $$item[1];
2508 } else {
2509 92 push(@defs, $item);
2510 }
2511 }
2512 23 ▶ if (@defs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@defs) 22 1 23
2513 22 $GBL{'fld'}{'def'}{$pkg} = \@defs;
2514 }
2515 }
2516 }
2517  
2518 # Add field info for dump()
2519 173 my $dump = $GBL{'dump'}{'fld'};
2520 173 ▶ $$dump{$pkg} ||= {};
Condition100%2/2
$dump->{$pkg} ||= {}
l!l
12647
MC/DC100%1/1
$dump->{$pkg} ||= {}
$dump->{$pkg}
Truth table100%2/2
A
A= $dump->{$pkg}
Aresult
11
00
2521 173 $dump = $$dump{$pkg};
2522  
2523 173 ▶ if ($name) {
Branch: 4 branches
BranchTrueFalseTotal
if ($name) { } 44 129 173
elsif ($get) { } 104 25 129
elsif ($set) { } 1 24 25
elsif (not $return || $lvalue || $delegate) { } 20 4 24
2524 44 ▶ if (add_dump_field('Name', $name, $field_ref, $dump) eq 'conflict') {
Branch: 1 branch
BranchTrueFalseTotal
if (add_dump_field("Name", $name, $field_ref, $dump) eq "conflict") 0 44 44
2525 0 OIO::Attribute->die(
2526 'message' => "Can't create accessor method for package '$pkg'",
2527 'Info' => "'$name' already specified for another field using '$$dump{$name}{'src'}'",
2528 'Attribute' => $attr);
2529 }
2530 # Done if only 'Name' present
2531 44 ▶ if (! $get && ! $set && ! $return && ! $lvalue) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($get or $set or $return or $lvalue) 22 22 44
Condition66%6/9
$get or $set or $return or $lvalue
l!l&&r!l&&!r
22022
$get or $set or $return
l!l&&r!l&&!r
22022
$get or $set
l!l&&r!l&&!r
22022
MC/DC25%1/4
$get or $set or $return or $lvalue
$get $set $return $lvalue
Truth table40%2/5
A or B or C or D
A= $getB= $setC= $returnD= $lvalue
ABCDresult
1XXX1
01XX1
001X1
00011
00000
2532 22 return;
2533 }
2534 } elsif ($get) {
2535 104 ▶ if (add_dump_field('Get', $get, $field_ref, $dump) eq 'conflict') {
Branch: 1 branch
BranchTrueFalseTotal
if (add_dump_field("Get", $get, $field_ref, $dump) eq "conflict") 0 104 104
2536 0 OIO::Attribute->die(
2537 'message' => "Can't create accessor method for package '$pkg'",
2538 'Info' => "'$get' already specified for another field using '$$dump{$get}{'src'}'",
2539 'Attribute' => $attr);
2540 }
2541 } elsif ($set) {
2542 1 ▶ if (add_dump_field('Set', $set, $field_ref, $dump) eq 'conflict') {
Branch: 1 branch
BranchTrueFalseTotal
if (add_dump_field("Set", $set, $field_ref, $dump) eq "conflict") 0 1 1
2543 0 OIO::Attribute->die(
2544 'message' => "Can't create accessor method for package '$pkg'",
2545 'Info' => "'$set' already specified for another field using '$$dump{$set}{'src'}'",
2546 'Attribute' => $attr);
2547 }
2548 ▶ } elsif (! $return && ! $lvalue && ! $delegate) {
Condition50%3/6
$return || $lvalue || $delegate
l!l&&r!l&&!r
0420
$return or $lvalue
l!l&&r!l&&!r
0024
MC/DC33%1/3
$return || $lvalue || $delegate
$return $lvalue $delegate
Truth table50%2/4
A or B || C
A= $returnB= $lvalueC= $delegate
ABCresult
1XX1
01X1
0011
0000
2549 20 return;
2550 }
2551  
2552 # If 'RETURN' or 'LVALUE', need 'SET', too
2553 131 ▶ if (($return || $lvalue) && ! $set) {
Branch: 1 branch
BranchTrueFalseTotal
if ($return || $lvalue and not $set) 0 131 131
Condition66%4/6
$return || $lvalue and not $set
!ll&&!rl&&r
116150
$return or $lvalue
l!l&&r!l&&!r
150116
MC/DC0%0/3
$return || $lvalue and not $set
$return $lvalue not $set
Truth table40%2/5
A or B and not(C)
A= $returnB= $lvalueC= not $set
ABCresult
00X0
1X00
0100
1X11
0111
2554 0 OIO::Attribute->die(
2555 'message' => "Can't create accessor method for package '$pkg'",
2556 'Info' => "No set accessor specified to go with 'RETURN'/'LVALUE'",
2557 'Attribute' => $attr);
2558 }
2559  
2560 # Check for name conflict
2561 131 foreach my $method ($get, $set) {
2562 262 ▶ if ($method) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method) 219 43 262
2563 44 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2564 # Do not overwrite existing methods
2565 219 ▶ if (*{$pkg.'::'.$method}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*{$pkg . '::' . $method;}{"CODE"}) 0 219 219
2566 0 OIO::Attribute->die(
2567 'message' => q/Can't create accessor method/,
2568 'Info' => "Method '$method' already exists in class '$pkg'",
2569 'Attribute' => $attr);
2570 }
2571 }
2572 }
2573  
2574 # Check return type and set default
2575 131 ▶ if (! defined($return) || $return eq 'NEW') {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $return or $return eq 'NEW') { } 121 10 131
elsif ($return eq 'OLD' or $return =~ /^PREV(?:IOUS)?$/ or $return eq 'PRIOR') { } 5 5 10
elsif ($return eq 'SELF' or $return =~ /^OBJ(?:ECT)?$/) { } 5 0 5
Condition100%3/3
not defined $return or $return eq "NEW"
l!l&&r!l&&!r
116510
MC/DC100%2/2
not defined $return or $return eq "NEW"
not defined $return $return eq "NEW"
Truth table100%3/3
not(A) or B
A= not defined $returnB= $return eq "NEW"
ABresult
1X1
011
000
2576 121 $return = 'NEW';
2577 ▶ } elsif ($return eq 'OLD' || $return =~ /^PREV(?:IOUS)?$/ || $return eq 'PRIOR') {
Condition83%5/6
$return eq "OLD" or $return =~ /^PREV(?:IOUS)?$/ or $return eq "PRIOR"
l!l&&r!l&&!r
505
$return eq "OLD" or $return =~ /^PREV(?:IOUS)?$/
l!l&&r!l&&!r
415
MC/DC66%2/3
$return eq "OLD" or $return =~ /^PREV(?:IOUS)?$/ or $return eq "PRIOR"
$return eq "OLD" $return =~ /^PREV(?:IOUS)?$/ $return eq "PRIOR"
Truth table75%3/4
A or B or C
A= $return eq "OLD"B= $return =~ /^PREV(?:IOUS)?$/C= $return eq "PRIOR"
ABCresult
1XX1
01X1
0011
0000
2578 5 $return = 'OLD';
2579 ▶ } elsif ($return eq 'SELF' || $return =~ /^OBJ(?:ECT)?$/) {
Condition66%2/3
$return eq "SELF" or $return =~ /^OBJ(?:ECT)?$/
l!l&&r!l&&!r
230
MC/DC0%0/2
$return eq "SELF" or $return =~ /^OBJ(?:ECT)?$/
$return eq "SELF" $return =~ /^OBJ(?:ECT)?$/
Truth table66%2/3
A or B
A= $return eq "SELF"B= $return =~ /^OBJ(?:ECT)?$/
ABresult
1X1
011
000
2580 5 $return = 'SELF';
2581 } else {
2582 0 OIO::Attribute->die(
2583 'message' => q/Can't create accessor method/,
2584 'Info' => "Invalid setting for 'RETURN': $return",
2585 'Attribute' => $attr);
2586 }
2587  
2588 # Get type checking (if any)
2589 131 my ($type, $subtype, $is_ref) = ('NONE', '', 0);
2590 131 ▶ if ($$fld_type{$field_ref}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fld_type->{$field_ref}) 50 81 131
2591 50 $type = $$fld_type{$field_ref}{'type'};
2592 50 ▶ if (! ref($type)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $type) 42 8 50
2593 42 ▶ if ($type =~ /^(.*)\((.+)\)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^(.*)\((.+)\)$/i) 3 39 42
2594 3 $type = $1;
2595 3 $subtype = $2;
2596 }
2597 42 ▶ if ($type =~ /^(HASH|ARRAY|SCALAR)_ref$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^(HASH|ARRAY|SCALAR)_ref$/) 7 35 42
2598 7 $type = $1;
2599 7 $is_ref = 1;
2600 }
2601 }
2602 }
2603 131 ▶ if ($subtype && ($type ne 'list' && $type ne 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subtype and ($type ne "list" and $type ne "ARRAY")) 0 131 131
Condition66%4/6
$subtype and ($type ne "list" and $type ne "ARRAY")
!ll&&!rl&&r
12830
$type ne "list" and $type ne "ARRAY"
!ll&&!rl&&r
210
MC/DC0%0/3
$subtype and ($type ne "list" and $type ne "ARRAY")
$subtype $type ne "list" $type ne "ARRAY"
Truth table50%2/4
A and B and C
A= $subtypeB= $type ne "list"C= $type ne "ARRAY"
ABCresult
0XX0
10X0
1100
1111
2604 0 OIO::Attribute->die(
2605 'message' => "Invalid type specification for package '$pkg'",
2606 'Info' => "Type '$type' cannot have subtypes",
2607 'Attribute' => $attr);
2608 }
2609  
2610 # Metadata
2611 131 my %meta;
2612 131 ▶ if ($set) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set) 93 38 131
2613 93 ▶ $meta{$set}{'kind'} = ($get && ($get eq $set)) ? 'accessor' : 'set';
Branch: 1 branch
BranchTrueFalseTotal
$get && $get eq $set ? : 70 23 93
Condition100%3/3
$get and $get eq $set
!ll&&!rl&&r
12270
MC/DC100%2/2
$get and $get eq $set
$get $get eq $set
Truth table100%3/3
A and B
A= $getB= $get eq $set
ABresult
0X0
100
111
2614 93 ▶ if ($lvalue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lvalue) 0 93 93
2615 0 $meta{$set}{'lvalue'} = 1;
2616 }
2617 93 $meta{$set}{'return'} = lc($return);
2618 # Type
2619 93 ▶ if (ref($type)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $type) { } 7 86 93
elsif ($type ne 'NONE') { } 38 48 86
2620 7 $meta{$set}{'type'} = $$fld_type{$field_ref}{'code'};
2621 } elsif ($type ne 'NONE') {
2622 38 $meta{$set}{'type'} = $type;
2623 }
2624 93 ▶ if ($subtype) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subtype) 3 90 93
2625 3 $meta{$set}{'type'} .= "($subtype)";
2626 }
2627 }
2628 131 ▶ if ($get && (!$set || ($get ne $set))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get and !$set || $get ne $set) 56 75 131
Condition100%6/6
$get and !$set || $get ne $set
!ll&&!rl&&r
510323
not $set or $get ne $set
l!l&&r!l&&!r
342270
MC/DC66%2/3
$get and !$set || $get ne $set
$get not $set $get ne $set
Truth table75%3/4
A and not(B) or C
A= $getB= not $setC= $get ne $set
ABCresult
0XX0
1000
11X1
1011
2629 56 $meta{$get}{'kind'} = 'get';
2630 }
2631 131 foreach my $meth ($get, $set) {
2632 262 ▶ next if (! $meth);
Branch: 1 branch
BranchTrueFalseTotal
unless $meth 43 219 262
2633 # Permissions
2634 219 ▶ if (defined($private)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $private) { } 2 217 219
elsif (defined $restricted) { } 4 213 217
2635 2 $meta{$meth}{'hidden'} = 1;
2636 } elsif (defined($restricted)) {
2637 4 $meta{$meth}{'restricted'} = 1;
2638 }
2639 }
2640 131 add_meta($pkg, \%meta);
2641  
2642 131 my $weak = $GBL{'fld'}{'weak'}{$field_ref};
2643  
2644 # Code to be eval'ed into subroutines
2645 131 my $code = "package $pkg;\n";
2646  
2647 # Create an :lvalue accessor
2648 131 ▶ if ($lvalue) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lvalue) { } 0 131 131
elsif ($set) { } 93 38 131
2649 0 $code .= create_lvalue_accessor($pkg, $set, $field_ref, $get,
2650 $type, $is_ref, $subtype,
2651 $name, $return, $private,
2652 $restricted, $weak, $pre);
2653 }
2654  
2655 # Create 'set' or combination accessor
2656 elsif ($set) {
2657 # Begin with subroutine declaration in the appropriate package
2658 93 $code .= "*${pkg}::$set = sub {\n";
2659  
2660 93 $code .= preamble_code($pkg, $set, $private, $restricted);
2661  
2662 93 ▶ my $fld_str = (ref($field_ref) eq 'HASH') ? "\$field->\{\${\$_[0]}}" : "\$field->\[\${\$_[0]}]";
Branch: 1 branch
BranchTrueFalseTotal
ref $field_ref eq 'HASH' ? : 14 79 93
2663  
2664 # Add GET portion for combination accessor
2665 93 ▶ if ($get && ($get eq $set)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get and $get eq $set) { } 70 23 93
Condition100%3/3
$get and $get eq $set
!ll&&!rl&&r
12270
MC/DC100%2/2
$get and $get eq $set
$get $get eq $set
Truth table100%3/3
A and B
A= $getB= $get eq $set
ABresult
0X0
100
111
2666 70 $code .= " return ($fld_str) if (\@_ == 1);\n";
2667 }
2668  
2669 # If set only, then must have at least one arg
2670 else {
2671 23 $code .= <<"_CHECK_ARGS_";
2672 if (\@_ < 2) {
2673 OIO::Args->die(
2674 'message' => q/Missing arg(s) to '$pkg->$set'/,
2675 'location' => [ caller() ]);
2676 }
2677 _CHECK_ARGS_
2678 }
2679  
2680 # Add preprocessing code block
2681 93 ▶ if ($pre) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre) 0 93 93
2682 0 $code .= <<"_PRE_";
2683 {
2684 my \@errs;
2685 local \$SIG{'__WARN__'} = sub { push(\@errs, \@_); };
2686 eval {
2687 my \$self = shift;
2688 \@_ = (\$self, \$preproc->(\$self, \$field, \@_));
2689 };
2690 if (\$@ || \@errs) {
2691 my (\$err) = split(/ at /, \$@ || join(" | ", \@errs));
2692 OIO::Code->die(
2693 'message' => q/Problem with preprocessing routine for '$pkg->$set'/,
2694 'Error' => \$err);
2695 }
2696 }
2697 _PRE_
2698 }
2699  
2700 # Add data type checking
2701 93 my ($type_code, $arg_str) = type_code($pkg, $set, $weak,
2702 $type, $is_ref, $subtype);
2703 93 $code .= $type_code;
2704  
2705 # Add field locking code if sharing
2706 93 ▶ if (is_sharing($pkg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_sharing($pkg)) 0 93 93
2707 0 $code .= " lock(\$field);\n"
2708 }
2709  
2710 # Grab 'OLD' value
2711 93 ▶ if ($return eq 'OLD') {
Branch: 1 branch
BranchTrueFalseTotal
if ($return eq "OLD") 5 88 93
2712 5 $code .= " my \$ret = $fld_str;\n";
2713 }
2714  
2715 # Add actual 'set' code
2716 93 ▶ $code .= (is_sharing($pkg))
Branch: 1 branch
BranchTrueFalseTotal
is_sharing($pkg) ? : 0 93 93
2717 ? " $fld_str = Object::InsideOut::Util::make_shared($arg_str);\n"
2718 : " $fld_str = $arg_str;\n";
2719 93 ▶ if ($weak) {
Branch: 1 branch
BranchTrueFalseTotal
if ($weak) 1 92 93
2720 1 $code .= " Scalar::Util::weaken($fld_str);\n";
2721 }
2722  
2723 # Add code for return value
2724 93 ▶ if ($return eq 'SELF') {
Branch: 4 branches
BranchTrueFalseTotal
if ($return eq 'SELF') { } 5 88 93
elsif ($return eq 'OLD') { } 5 83 88
elsif ($use_want) { } 4 79 83
elsif ($weak) { } 1 78 79
2725 5 $code .= " \$_[0];\n";
2726 } elsif ($return eq 'OLD') {
2727 5 ▶ if ($use_want) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_want) 4 1 5
2728 4 $code .= " ((Want::wantref() eq 'OBJECT') && !Scalar::Util::blessed(\$ret)) ? \$_[0] : ";
2729 }
2730 5 $code .= "\$ret;\n";
2731 } elsif ($use_want) {
2732 4 $code .= " ((Want::wantref() eq 'OBJECT') && !Scalar::Util::blessed($fld_str)) ? \$_[0] : $fld_str;\n";
2733 } elsif ($weak) {
2734 1 $code .= " $fld_str;\n";
2735 }
2736  
2737 # Done
2738 93 $code .= "};\n";
2739 }
2740 131 ▶ undef($type) if (! ref($type));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $type 123 8 131
2741  
2742 # Create 'get' accessor
2743 131 ▶ if ($get && (!$set || ($get ne $set))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get and !$set || $get ne $set) 56 75 131
Condition100%6/6
$get and !$set || $get ne $set
!ll&&!rl&&r
510323
not $set or $get ne $set
l!l&&r!l&&!r
342270
MC/DC66%2/3
$get and !$set || $get ne $set
$get not $set $get ne $set
Truth table75%3/4
A and not(B) or C
A= $getB= not $setC= $get ne $set
ABCresult
0XX0
1000
11X1
1011
2744 56 ▶ $code .= "*${pkg}::$get = sub {\n"
Branch: 1 branch
BranchTrueFalseTotal
ref $field_ref eq 'HASH' ? : 4 52 56
2745  
2746 . preamble_code($pkg, $get, $private, $restricted, 'readonly')
2747  
2748 . ((ref($field_ref) eq 'HASH')
2749 ? " \$field->{\${\$_[0]}};\n};\n"
2750 : " \$field->[\${\$_[0]}];\n};\n");
2751 }
2752  
2753 # Create delegation accessor
2754 131 ▶ if ($delegate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delegate) 7 124 131
2755 7 $delegate =~ s/\s*-->\s*/-->/g;
2756 7 my @methods = split(/[,\s]+/, $delegate);
2757 7 @methods = grep { $_ } @methods;
2758 7 @methods = map { get_class_methods($pkg, $_) } @methods;
2759 7 for my $method (@methods) {
2760 12 my ($from, $to) = split(/-->/, $method);
2761 12 ▶ if (! defined($to)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $to) 9 3 12
2762 9 $to = $from;
2763 }
2764 44 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2765 12 ▶ if (*{$pkg.'::'.$from}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*{$pkg . '::' . $from;}{"CODE"}) 0 12 12
2766 0 OIO::Attribute->die(
2767 'message' => q/Can't create delegator method/,
2768 'Info' => "Method '$from' already exists in class '$pkg'",
2769 'Attribute' => $attr);
2770 }
2771 12 ▶ $code .= "*${pkg}::$from = sub {\n"
Branch: 1 branch
BranchTrueFalseTotal
ref $field_ref eq 'HASH' ? : 0 12 12
2772  
2773 . preamble_code($pkg, $method, $private, $restricted)
2774  
2775 . " my \$self = shift;\n"
2776  
2777 . ((ref($field_ref) eq 'HASH')
2778 ? " \$field->{\${\$self}}->$to(\@_);\n};\n"
2779 : " \$field->[\${\$self}]->$to(\@_);\n};\n");
2780 }
2781 }
2782  
2783 # Compile the subroutine(s) in the smallest possible lexical scope
2784 131 my @errs;
2785 131 ▶ local $SIG{'__WARN__'} = sub { push(@errs, @_); };
Subroutine __ANON__: not called CC=1 SCAR=1.2
2786 {
2787 131 my $field = $field_ref;
2788 131 my $type_check = $type;
2789 131 my $preproc = $pre;
2790 131 ▶ eval $code;
Branch: 2 branches
BranchTrueFalseTotal
if (@_ > 1) 2 9 11
if (@_ < 2) 0 8 8
2791 }
2792 131 ▶ if ($@ || @errs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or @errs) 0 131 131
Condition33%1/3
$@ or @errs
l!l&&r!l&&!r
00131
MC/DC0%0/2
$@ or @errs
$@ @errs
Truth table33%1/3
A or B
A= $@B= @errs
ABresult
1X1
011
000
2793 0 ▶ my ($err) = split(/ at /, $@ || join(" | ", @errs));
Condition0%0/3
$@ || join(' | ', @errs)
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || join(' | ', @errs)
$@ join(' | ', @errs)
Truth table0%0/3
A || B
A= $@B= join(' | ', @errs)
ABresult
1X1
011
000
2794 0 OIO::Internal->die(
2795 'message' => "Failure creating accessor for class '$pkg'",
2796 'Error' => $err,
2797 'Declaration' => $attr,
2798 'Code' => $code,
2799 'self' => 1);
2800 }
2801 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2802  
2803  
2804 # Generate code for start of accessor
2805 sub preamble_code :Sub(Private)
2806 {
2807 244 ▶ my ($pkg, $name, $private, $restricted, $readonly) = @_;
Subroutine preamble_code: called CC=4 SCAR=13.9
Pod undocumented
2808 211 my $code = '';
2809  
2810 # Argument checking code
2811 197 ▶ if (defined($readonly)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $readonly) 103 140 243
2812 84 $code = <<"_READONLY_";
2813 if (\@_ > 1) {
2814 OIO::Method->die('message' => "Can't call readonly accessor method '$pkg->$name' with an argument");
2815 }
2816 _READONLY_
2817 }
2818  
2819 # Permission checking code
2820 221 ▶ if (defined($private)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $private) { } 18 201 219
elsif (defined $restricted) { } 19 178 197
2821 30 $code = <<"_PRIVATE_";
2822 my \$caller = caller();
2823 if (! grep { \$_ eq \$caller } ($private)) {
2824 OIO::Method->die('message' => "Can't call private method '$pkg->$name' from class '\$caller'");
2825 }
2826 _PRIVATE_
2827 } elsif (defined($restricted)) {
2828 46 $code = <<"_RESTRICTED_";
2829 my \$caller = caller();
2830 if (! ((grep { \$_ eq \$caller } ($restricted)) ||
2831 \$caller->isa('$pkg') ||
2832 $pkg->isa(\$caller)))
2833 {
2834 OIO::Method->die('message' => "Can't call restricted method '$pkg->$name' from class '\$caller'");
2835 }
2836 _RESTRICTED_
2837 }
2838  
2839 213 return ($code);
2840 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2841  
2842  
2843 # Generate type checking code
2844 sub type_code :Sub(Private)
2845 {
2846 124 ▶ my ($pkg, $name, $weak, $type, $is_ref, $subtype) = @_;
Subroutine type_code: called CC=12 SCAR=24.8
Pod undocumented
2847 108 my $code = '';
2848 113 my $arg_str = '$_[1]';
2849  
2850 # Type checking code
2851 114 ▶ if (ref($type)) {
Branch: 6 branches
BranchTrueFalseTotal
if (ref $type) { } 12 104 116
elsif ($type eq 'NONE') { } 59 64 123
elsif ($type eq 'scalar') { } 7 60 67
elsif ($type eq 'numeric') { } 16 57 73
elsif ($type eq 'list') { } 11 54 65
elsif ($type eq 'HASH' and not $is_ref) { } 17 33 50
2852 23 $code = <<"_CODE_";
2853 {
2854 my (\$ok, \@errs);
2855 local \$SIG{'__WARN__'} = sub { push(\@errs, \@_); };
2856 eval { \$ok = \$type_check->($arg_str) };
2857 if (\$@ || \@errs) {
2858 my (\$err) = split(/ at /, \$@ || join(" | ", \@errs));
2859 OIO::Code->die(
2860 'message' => q/Problem with type check routine for '$pkg->$name'/,
2861 'Error' => \$err);
2862 }
2863 if (! \$ok) {
2864 OIO::Args->die(
2865 'message' => "Argument to '$pkg->$name' failed type check: $arg_str",
2866 'location' => [ caller() ]);
2867 }
2868 }
2869 _CODE_
2870  
2871 } elsif ($type eq 'NONE') {
2872 # For 'weak' fields, the data must be a ref
2873 58 ▶ if ($weak) {
Branch: 1 branch
BranchTrueFalseTotal
if ($weak) 5 57 62
2874 38 $code = <<"_WEAK_";
2875 if (! ref($arg_str)) {
2876 OIO::Args->die(
2877 'message' => "Bad argument: $arg_str",
2878 'Usage' => q/Argument to '$pkg->$name' must be a reference/,
2879 'location' => [ caller() ]);
2880 }
2881 _WEAK_
2882 }
2883  
2884 } elsif ($type eq 'scalar') {
2885 # One scalar argument
2886 15 $code = <<"_SCALAR_";
2887 if (ref($arg_str)) {
2888 OIO::Args->die(
2889 'message' => "Bad argument: $arg_str",
2890 'Usage' => q/Argument to '$pkg->$name' must be a scalar/,
2891 'location' => [ caller() ]);
2892 }
2893 _SCALAR_
2894  
2895 } elsif ($type eq 'numeric') {
2896 # One numeric argument
2897 47 $code = <<"_NUMERIC_";
2898 if (! Scalar::Util::looks_like_number($arg_str)) {
2899 OIO::Args->die(
2900 'message' => "Bad argument: $arg_str",
2901 'Usage' => q/Argument to '$pkg->$name' must be a number/,
2902 'location' => [ caller() ]);
2903 }
2904 _NUMERIC_
2905  
2906 } elsif ($type eq 'list') {
2907 # List/array - 1+ args or array ref
2908 38 $code = <<'_ARRAY_';
2909 my $arg;
2910 if (@_ == 2 && ref($_[1]) eq 'ARRAY') {
2911 $arg = $_[1];
2912 } else {
2913 my @args = @_;
2914 shift(@args);
2915 $arg = \@args;
2916 }
2917 _ARRAY_
2918 26 $arg_str = '$arg';
2919  
2920 ▶ } elsif ($type eq 'HASH' && !$is_ref) {
Condition100%3/3
$type eq "HASH" and not $is_ref
!ll&&!rl&&r
2138
MC/DC100%2/2
$type eq "HASH" and not $is_ref
$type eq "HASH" not $is_ref
Truth table100%3/3
A and not(B)
A= $type eq "HASH"B= not $is_ref
ABresult
0X0
100
111
2921 # Hash - pairs of args or hash ref
2922 16 $code = <<"_HASH_";
2923 my \$arg;
2924 if (\@_ == 2 && ref(\$_[1]) eq 'HASH') {
2925 \$arg = \$_[1];
2926 } elsif (\@_ % 2 == 0) {
2927 OIO::Args->die(
2928 'message' => q/Odd number of arguments: Can't create hash ref/,
2929 'Usage' => q/'$pkg->$name' requires a hash ref or an even number of args (to make a hash ref)/,
2930 'location' => [ caller() ]);
2931 } else {
2932 my \@args = \@_;
2933 shift(\@args);
2934 my \%args = \@args;
2935 \$arg = \\\%args;
2936 }
2937 _HASH_
2938 20 $arg_str = '$arg';
2939  
2940 } else {
2941 # One object or ref arg - exact spelling and case required
2942 31 $code = <<"_REF_";
2943 if (! Object::InsideOut::Util::is_it($arg_str, '$type')) {
2944 OIO::Args->die(
2945 'message' => q/Bad argument: Wrong type/,
2946 'Usage' => q/Argument to '$pkg->$name' must be of type '$type'/,
2947 'location' => [ caller() ]);
2948 }
2949 _REF_
2950 }
2951  
2952 # Subtype checking code
2953 126 ▶ if ($subtype) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subtype) 5 109 114
2954 26 ▶ if ($subtype =~ /^scalar$/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($subtype =~ /^scalar$/i) { } 14 17 31
elsif ($subtype =~ /^num(?:ber|eric)?$/i) { } 5 12 17
2955 27 $code .= <<"_SCALAR_SUBTYPE_";
2956 foreach my \$elem (\@{$arg_str}) {
2957 if (ref(\$elem)) {
2958 OIO::Args->die(
2959 'message' => q/Bad argument: Wrong type/,
2960 'Usage' => q/Values to '$pkg->$name' must be scalars/,
2961 'location' => [ caller() ]);
2962 }
2963 }
2964 _SCALAR_SUBTYPE_
2965 } elsif ($subtype =~ /^num(?:ber|eric)?$/i) {
2966 29 $code .= <<"_NUM_SUBTYPE_";
2967 foreach my \$elem (\@{$arg_str}) {
2968 if (! Scalar::Util::looks_like_number(\$elem)) {
2969 OIO::Args->die(
2970 'message' => q/Bad argument: Wrong type/,
2971 'Usage' => q/Values to '$pkg->$name' must be numeric/,
2972 'location' => [ caller() ]);
2973 }
2974 }
2975 _NUM_SUBTYPE_
2976 } else {
2977 22 $code .= <<"_SUBTYPE_";
2978 foreach my \$elem (\@{$arg_str}) {
2979 if (! Object::InsideOut::Util::is_it(\$elem, '$subtype')) {
2980 OIO::Args->die(
2981 'message' => q/Bad argument: Wrong type/,
2982 'Usage' => q/Values to '$pkg->$name' must be of type '$subtype'/,
2983 'location' => [ caller() ]);
2984 }
2985 }
2986 _SUBTYPE_
2987 }
2988 }
2989  
2990 111 return ($code, $arg_str);
2991 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
2992  
2993  
2994 ### Wrappers ###
2995  
2996 # Returns a 'wrapper' closure back to initialize() that adds merged argument
2997 # support for a method.
2998 sub wrap_MERGE_ARGS :Sub(Private)
2999 {
3000 87 ▶ my $code = shift;
Subroutine wrap_MERGE_ARGS: called CC=1 SCAR=0.0
Pod undocumented
3001 return sub {
3002 231 ▶ my $self = shift;
Subroutine __ANON__: called CC=5 SCAR=16.1
3003  
3004 # Gather arguments into a single hash ref
3005 219 my $args = {};
3006 201 ▶ while (my $arg = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = shift()) 138 197 335
3007 133 ▶ if (ref($arg) eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $arg eq 'HASH') { } 22 119 141
elsif (ref $arg) { } 2 118 120
elsif (not @_) { } 8 119 127
3008 # Add args from a hash ref
3009 38 @{$args}{keys(%{$arg})} = values(%{$arg});
3010 } elsif (ref($arg)) {
3011 10 OIO::Args->die(
3012 24 'message' => "Bad initializer: @{[ref($arg)]} ref not allowed",
3013 'Usage' => q/Args must be 'key=>val' pair(s) and\/or hash ref(s)/);
3014 } elsif (! @_) {
3015 20 OIO::Args->die(
3016 'message' => "Bad initializer: Missing value for key '$arg'",
3017 'Usage' => q/Args must be 'key=>val' pair(s) and\/or hash ref(s)/);
3018 } else {
3019 # Add 'key => value' pair
3020 118 $$args{$arg} = shift;
3021 }
3022 }
3023  
3024 206 @_ = ($self, $args);
3025 204 goto $code;
3026 72 };
3027 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3028  
3029  
3030 # Returns a 'wrapper' closure back to initialize() that restricts a method
3031 # to being only callable from within its class hierarchy
3032 sub wrap_RESTRICTED :Sub(Private)
3033 {
3034 28 ▶ my ($pkg, $method, $code, $exempt) = @_;
Subroutine wrap_RESTRICTED: called CC=1 SCAR=0.0
Pod undocumented
3035 return sub {
3036 # Caller must be in class hierarchy, or be specified as an exemption
3037 51 ▶ my $caller = caller();
Subroutine __ANON__: called CC=4 SCAR=13.9
3038 50 ▶ if (! ((grep { $_ eq $caller } @$exempt) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $caller;} @$exempt or $caller->isa($pkg) or $pkg->isa($caller)) 5 44 49
Condition100%6/6
grep {$_ eq $caller;} @$exempt or $caller->isa($pkg) or $pkg->isa($caller)
l!l&&r!l&&!r
19205
grep {$_ eq $caller;} @$exempt or $caller->isa($pkg)
l!l&&r!l&&!r
91429
MC/DC100%3/3
grep {$_ eq $caller;} @$exempt or $caller->isa($pkg) or $pkg->isa($caller)
grep {$_ eq $caller;} @$exempt $caller->isa($pkg) $pkg->isa($caller)
Truth table100%4/4
A or B or C
A= grep {$_ eq $caller;} @$exemptB= $caller->isa($pkg)C= $pkg->isa($caller)
ABCresult
1XX1
01X1
0011
0000
3039 $caller->isa($pkg) ||
3040 $pkg->isa($caller)))
3041 {
3042 18 OIO::Method->die('message' => "Can't call restricted method '$pkg->$method' from class '$caller'");
3043 }
3044 43 goto $code;
3045 15 };
3046 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3047  
3048  
3049 # Returns a 'wrapper' closure back to initialize() that makes a method
3050 # private (i.e., only callable from within its own class).
3051 sub wrap_PRIVATE :Sub(Private)
3052 {
3053 1175 ▶ my ($pkg, $method, $code, $exempt) = @_;
Subroutine wrap_PRIVATE: called CC=1 SCAR=0.0
Pod undocumented
3054 return sub {
3055 # Caller must be in the package, or be specified as an exemption
3056 3208 ▶ my $caller = caller();
Subroutine __ANON__: called CC=2 SCAR=6.9
3057 3211 ▶ if (! grep { $_ eq $caller } @$exempt) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $caller;} @$exempt) 6 3207 3213
3058 17 OIO::Method->die('message' => "Can't call private method '$pkg->$method' from class '$caller'");
3059 }
3060 3208 goto $code;
3061 1180 };
3062 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3063  
3064  
3065 # Returns a 'wrapper' closure back to initialize() that makes a subroutine
3066 # uncallable - with the original code ref stored elsewhere, of course.
3067 sub wrap_HIDDEN :Sub(Private)
3068 {
3069 47 ▶ my ($pkg, $method) = @_;
Subroutine wrap_HIDDEN: called CC=1 SCAR=0.0
Pod undocumented
3070 return sub {
3071 9 ▶ OIO::Method->die('message' => "Can't call hidden method '$pkg->$method'");
Subroutine __ANON__: not called CC=1 SCAR=0.0
3072 }
3073 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3074  
3075  
3076 ### Delayed Loading ###
3077  
3078 # Loads sub-modules
3079 sub load :Sub(Private)
3080 {
3081 41 ▶ my $mod = shift;
Subroutine load: called CC=5 SCAR=16.1
Pod undocumented
3082 45 my $file = "Object/InsideOut/$mod.pm";
3083  
3084 42 ▶ if (! exists($INC{$file})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $INC{$file}) 47 15 62
3085 # Load the file
3086 45 my $rc = do($file);
3087  
3088 # Check for errors
3089 41 ▶ if ($@) {
Branch: 3 branches
BranchTrueFalseTotal
if ($@) { } 3 41 44
elsif (not defined $rc) { } 3 43 46
elsif (not $rc) { } 13 46 59
3090 25 OIO::Internal->die(
3091 'message' => "Failure compiling file '$file'",
3092 'Error' => $@,
3093 'self' => 1);
3094 } elsif (! defined($rc)) {
3095 19 OIO::Internal->die(
3096 'message' => "Failure reading file '$file'",
3097 'Error' => $!,
3098 'self' => 1);
3099 } elsif (! $rc) {
3100 16 OIO::Internal->die(
3101 'message' => "Failure processing file '$file'",
3102 'Error' => $rc,
3103 'self' => 1);
3104 }
3105 }
3106 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3107  
3108 sub generate_CUMULATIVE :Sub(Private)
3109 {
3110 6 ▶ load('Cumulative');
Subroutine generate_CUMULATIVE: not called CC=1 SCAR=0.0
Pod undocumented
3111 13 goto &generate_CUMULATIVE;
3112 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3113  
3114 sub create_CUMULATIVE :Sub(Private)
3115 {
3116 12 ▶ load('Cumulative');
Subroutine create_CUMULATIVE: not called CC=1 SCAR=0.0
Pod undocumented
3117 10 goto &create_CUMULATIVE;
3118 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3119  
3120 sub generate_CHAINED :Sub(Private)
3121 {
3122 3 ▶ load('Chained');
Subroutine generate_CHAINED: not called CC=1 SCAR=0.0
Pod undocumented
3123 16 goto &generate_CHAINED;
3124 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3125  
3126 sub create_CHAINED :Sub(Private)
3127 {
3128 25 ▶ load('Chained');
Subroutine create_CHAINED: not called CC=1 SCAR=0.0
Pod undocumented
3129 21 goto &create_CHAINED;
3130 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3131  
3132 sub generate_OVERLOAD :Sub(Private)
3133 {
3134 10 ▶ load('Overload');
Subroutine generate_OVERLOAD: not called CC=1 SCAR=0.0
Pod undocumented
3135 13 goto &generate_OVERLOAD;
3136 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3137  
3138 sub install_UNIVERSAL :Sub(Private)
3139 {
3140 12 ▶ load('Universal');
Subroutine install_UNIVERSAL: not called CC=1 SCAR=0.0
Pod undocumented
3141 8 @_ = (\%GBL);
3142 9 goto &install_UNIVERSAL;
3143 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3144  
3145 sub install_ATTRIBUTES :Sub
3146 {
3147 17 ▶ load('attributes');
Subroutine install_ATTRIBUTES: not called CC=1 SCAR=0.0
Pod undocumented
3148 6 goto &install_ATTRIBUTES;
3149 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3150  
3151 sub dump :Method(Object)
3152 {
3153 21 ▶ load('Dump');
Subroutine dump: called CC=1 SCAR=0.0
Pod documented
3154 20 @_ = (\%GBL, 'dump', @_);
3155 26 goto &dump;
3156 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3157  
3158 sub pump :Method(Class)
3159 {
3160 15 ▶ load('Dump');
Subroutine pump: not called CC=1 SCAR=0.0
Pod documented
3161 18 @_ = (\%GBL, 'pump', @_);
3162 24 goto &dump;
3163 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3164  
3165 sub inherit :Method(Object)
3166 {
3167 16 ▶ load('Foreign');
Subroutine inherit: not called CC=1 SCAR=0.0
Pod documented
3168 13 @_ = (\%GBL, 'inherit', @_);
3169 20 goto &inherit;
3170 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3171  
3172 sub heritage :Method(Object)
3173 {
3174 14 ▶ load('Foreign');
Subroutine heritage: not called CC=1 SCAR=0.0
Pod documented
3175 17 @_ = (\%GBL, 'heritage', @_);
3176 17 goto &inherit;
3177 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3178  
3179 sub disinherit :Method(Object)
3180 {
3181 14 ▶ load('Foreign');
Subroutine disinherit: not called CC=1 SCAR=0.0
Pod documented
3182 5 @_ = (\%GBL, 'disinherit', @_);
3183 15 goto &inherit;
3184 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3185  
3186 sub create_heritage :Sub(Private)
3187 {
3188 13 ▶ load('Foreign');
Subroutine create_heritage: not called CC=1 SCAR=0.0
Pod undocumented
3189 5 @_ = (\%GBL, 'create_heritage', @_);
3190 4 goto &inherit;
3191 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3192  
3193 sub create_field :Method(Class)
3194 {
3195 4 ▶ load('Dynamic');
Subroutine create_field: called CC=1 SCAR=0.0
Pod undocumented
3196 4 @_ = (\%GBL, 'create_field', @_);
3197 7 goto &create_field;
3198 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3199  
3200 sub add_class :Method(Class)
3201 {
3202 3 ▶ load('Dynamic');
Subroutine add_class: called CC=1 SCAR=0.0
Pod documented
3203 3 @_ = (\%GBL, 'add_class', @_);
3204 2 goto &create_field;
3205 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3206  
3207 sub AUTOLOAD :Sub
3208 {
3209 6 ▶ load('Autoload');
Subroutine AUTOLOAD: called CC=1 SCAR=0.0
3210 6 @_ = (\%GBL, @_);
3211 5 goto &Object::InsideOut::AUTOLOAD;
3212 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3213  
3214 sub create_lvalue_accessor :Sub(Private)
3215 {
3216 0 ▶ load('lvalue');
Subroutine create_lvalue_accessor: not called CC=1 SCAR=6.9
Pod undocumented
3217 0 goto &create_lvalue_accessor;
3218 44 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
3219  
3220  
3221 ### Initialization and Termination ###
3222  
3223 # Initialize the package after loading
3224 44 initialize();
3225  
3226 {
3227 # Initialize as part of the CHECK phase
3228 44 ▶ no warnings 'void';
Subroutine BEGIN: called CC=1 SCAR=0.0
3229 CHECK {
3230 41 ▶ initialize();
Subroutine CHECK: called CC=1 SCAR=0.0
3231 }
3232 }
3233  
3234 # Initialize just before cloning a thread
3235 sub CLONE_SKIP
3236 44 {
3237 0 ▶ if ($_[0] eq 'Object::InsideOut') {
Subroutine CLONE_SKIP: not called CC=2 SCAR=10.5
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] eq "Object::InsideOut") 2 12 14
3238 0 initialize();
3239 }
3240 0 return 0;
3241 }
3242  
3243 # Workaround for Perl's "in cleanup" bug
3244 END {
3245 44 ▶ $GBL{'term'} = 1;
Subroutine END: called CC=1 SCAR=0.0
3246 }
3247  
3248 } # End of package's lexical scope
3249  
3250 44 1;
3251 # EOF
↑ Summary blib/lib/Object/InsideOut/Util.pm »