Object/InsideOut.pm

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