blib/lib/Object/InsideOut.pm

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