Object/InsideOut/Cumulative.pm

filter: Statementstmt 74.8% 152 / 203 Branchbran 50.0% 25 / 50 Conditioncond 32.2% 10 / 31 MC/DCmcdc 5.5% 1 / 18 Subroutinesub 87.5% 21 / 24 Podpod 0.0% 0 / 2 totaltotal 63.7% 209 / 328 CC 48 SCAR 42.0
CC
48
Cov
66%
generate_CUMULATIVE
128.6
__ANON__
23.4
as_hash
2.0
CRAP 66.6
« Object/InsideOut.pm ↑ Summary Object/InsideOut/Metadata.pm »
1 package Object::InsideOut; {
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 my $GBL = {};
8  
9 1 ▶sub generate_CUMULATIVE :Sub(Private)
Subroutine generate_CUMULATIVE: called CC=34 SCAR=48.6
Pod undocumented
10 {
11 1 ($GBL) = @_;
12 1 my $g_cu = $$GBL{'sub'}{'cumu'};
13 1 ▶ my $cumu_td = $$g_cu{'new'}{'td'} || [];
Condition50%1/2
$g_cu->{'new'}{'td'} || []
l!l
10
MC/DC0%0/1
$g_cu->{'new'}{'td'} || []
$g_cu->{'new'}{'td'}
Truth table50%1/2
A
A= $g_cu->{'new'}{'td'}
Aresult
11
00
14 1 ▶ my $cumu_bu = $$g_cu{'new'}{'bu'} || [];
Condition50%1/2
$g_cu->{'new'}{'bu'} || []
l!l
01
MC/DC0%0/1
$g_cu->{'new'}{'bu'} || []
$g_cu->{'new'}{'bu'}
Truth table50%1/2
A
A= $g_cu->{'new'}{'bu'}
Aresult
11
00
15 1 delete($$g_cu{'new'});
16 1 ▶ if (! exists($$g_cu{'td'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $g_cu->{"td"}) 1 0 1
17 1 $$GBL{'sub'}{'cumu'} = {
18 td => {}, # 'Top down'
19 bu => {}, # 'Bottom up'
20 restrict => {}, # :Restricted
21 };
22 1 $g_cu = $$GBL{'sub'}{'cumu'};
23 }
24 1 my $cu_td = $$g_cu{'td'};
25 1 my $cu_bu = $$g_cu{'bu'};
26 1 my $cu_restr = $$g_cu{'restrict'};
27  
28 # Get names for :CUMULATIVE methods
29 1 my (%cum_loc);
30 1 ▶ while (my $info = shift(@{$cumu_td})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = shift @{$cumu_td;}) 3 1 4
31 3 ▶ $$info{'name'} ||= sub_name($$info{'code'}, ':CUMULATIVE', $$info{'loc'});
Condition33%1/3
$info->{"name"} ||= sub_name($info->{"code"}, ":CUMULATIVE", $info->{"loc"})
l!l&&r!l&&!r
030
MC/DC0%0/2
$info->{"name"} ||= sub_name($info->{"code"}, ":CUMULATIVE", $info->{"loc"})
$info->{"name"} sub_name($info->{"code"}, ":CUMULATIVE", $info->{"loc"})
Truth table33%1/3
A ||= B
A= $info->{"name"}B= sub_name($info->{"code"}, ":CUMULATIVE", $info->{"loc"})
ABresult
1X1
011
000
32 3 my $package = $$info{'pkg'};
33 3 my $name = $$info{'name'};
34  
35 3 $cum_loc{$name}{$package} = $$info{'loc'};
36  
37 3 $$cu_td{$name}{$package} = $$info{'wrap'};
38 3 ▶ if (exists($$info{'exempt'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{"exempt"}) 3 0 3
39 3 push(@{$$cu_restr{$package}{$name}},
40 0 ▶ sort grep {$_} split(/[,'\s]+/, $$info{'exempt'} || ''));
Condition50%1/2
$info->{'exempt'} || ''
l!l
03
MC/DC0%0/1
$info->{'exempt'} || ''
$info->{'exempt'}
Truth table50%1/2
A
A= $info->{'exempt'}
Aresult
11
00
41 }
42 }
43  
44 # Get names for :CUMULATIVE(BOTTOM UP) methods
45 1 ▶ while (my $info = shift(@{$cumu_bu})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = shift @{$cumu_bu;}) 0 1 1
46 0 ▶ $$info{'name'} ||= sub_name($$info{'code'}, ':CUMULATIVE(BOTTOM UP)', $$info{'loc'});
Condition0%0/3
$info->{"name"} ||= sub_name($info->{"code"}, ":CUMULATIVE(BOTTOM UP)", $info->{"loc"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$info->{"name"} ||= sub_name($info->{"code"}, ":CUMULATIVE(BOTTOM UP)", $info->{"loc"})
$info->{"name"} sub_name($info->{"code"}, ":CUMULATIVE(BOTTOM UP)", $info->{"loc"})
Truth table0%0/3
A ||= B
A= $info->{"name"}B= sub_name($info->{"code"}, ":CUMULATIVE(BOTTOM UP)", $info->{"loc"})
ABresult
1X1
011
000
47 0 my $package = $$info{'pkg'};
48 0 my $name = $$info{'name'};
49  
50 # Check for conflicting definitions of 'name'
51 0 ▶ if ($$cu_td{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cu_td->{$name}) 0 0 0
52 0 foreach my $other_package (keys(%{$$cu_td{$name}})) {
53 0 ▶ if ($other_package->isa($package) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($other_package->isa($package) or $package->isa($other_package)) 0 0 0
Condition0%0/3
$other_package->isa($package) or $package->isa($other_package)
l!l&&r!l&&!r
000
MC/DC0%0/2
$other_package->isa($package) or $package->isa($other_package)
$other_package->isa($package) $package->isa($other_package)
Truth table0%0/3
A or B
A= $other_package->isa($package)B= $package->isa($other_package)
ABresult
1X1
011
000
54 $package->isa($other_package))
55 {
56 0 my ($pkg, $file, $line) = @{$cum_loc{$name}{$other_package}};
57 0 my ($pkg2, $file2, $line2) = @{$$info{'loc'}};
58 OIO::Attribute->die(
59 0 'location' => $$info{'loc'},
60 'message' => "Conflicting definitions for cumulative method '$name'",
61 'Info' => "Declared as :CUMULATIVE in class '$pkg' (file '$file', line $line), but declared as :CUMULATIVE(BOTTOM UP) in class '$pkg2' (file '$file2' line $line2)");
62 }
63 }
64 }
65  
66 0 $$cu_bu{$name}{$package} = $$info{'wrap'};
67 0 ▶ if (exists($$info{'exempt'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{"exempt"}) 0 0 0
68 0 push(@{$$cu_restr{$package}{$name}},
69 0 ▶ sort grep {$_} split(/[,'\s]+/, $$info{'exempt'} || ''));
Condition0%0/2
$info->{'exempt'} || ''
l!l
00
MC/DC0%0/1
$info->{'exempt'} || ''
$info->{'exempt'}
Truth table0%0/2
A
A= $info->{'exempt'}
Aresult
11
00
70 }
71 }
72  
73 # Propagate restrictions
74 1 my $reapply = 1;
75 1 my $trees = $$GBL{'tree'}{'td'};
76 1 ▶ while ($reapply) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reapply) 1 1 2
77 1 $reapply = 0;
78 1 foreach my $pkg (keys(%{$cu_restr})) {
79 3 foreach my $class (keys(%{$trees})) {
80 12 ▶ next if (! grep { $_ eq $pkg } @{$$trees{$class}});
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $pkg;} @{$$trees{$class};} 6 6 12
81 6 foreach my $p (@{$$trees{$class}}) {
82 14 foreach my $n (keys(%{$$cu_restr{$pkg}})) {
83 14 ▶ if (exists($$cu_restr{$p}{$n})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cu_restr->{$p}{$n}) { } 14 0 14
84 14 ▶ next if ($$cu_restr{$p}{$n} == $$cu_restr{$pkg}{$n});
Branch: 1 branch
BranchTrueFalseTotal
if $cu_restr->{$p}{$n} == $cu_restr->{$pkg}{$n} 12 2 14
85 2 my $equal = (@{$$cu_restr{$p}{$n}} == @{$$cu_restr{$pkg}{$n}});
86 2 ▶ if ($equal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($equal) 2 0 2
87 2 for (1..@{$$cu_restr{$p}{$n}}) {
88 0 ▶ if ($$cu_restr{$pkg}{$n}[$_-1] ne $$cu_restr{$p}{$n}[$_-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cu_restr->{$pkg}{$n}[$_ - 1] ne $cu_restr->{$p}{$n}[$_ - 1]) 0 0 0
89 0 $equal = 0;
90 0 last;
91 }
92 }
93 }
94 2 ▶ if (! $equal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($equal) 0 2 2
95 0 my %restr = map { $_ => 1 } @{$$cu_restr{$p}{$n}}, @{$$cu_restr{$pkg}{$n}};
96 0 $$cu_restr{$pkg}{$n} = [ sort(keys(%restr)) ];
97 0 $reapply = 1;
98 }
99 } else {
100 0 $reapply = 1;
101 }
102 2 $$cu_restr{$p}{$n} = $$cu_restr{$pkg}{$n};
103 }
104 }
105 }
106 }
107 }
108  
109 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
110 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112 # Implement :CUMULATIVE methods
113 1 foreach my $name (keys(%{$cu_td})) {
114 1 my $code = create_CUMULATIVE($name, $trees, $$cu_td{$name});
115 1 foreach my $package (keys(%{$$cu_td{$name}})) {
116 3 *{$package.'::'.$name} = $code;
117 3 add_meta($package, $name, 'kind', 'cumulative');
118 3 ▶ if (exists($$cu_restr{$package}{$name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cu_restr->{$package}{$name}) 3 0 3
119 3 add_meta($package, $name, 'restrict', 1);
120 }
121 }
122 }
123  
124 # Implement :CUMULATIVE(BOTTOM UP) methods
125 1 foreach my $name (keys(%{$cu_bu})) {
126 0 my $code = create_CUMULATIVE($name, $$GBL{'tree'}{'bu'}, $$cu_bu{$name});
127 0 foreach my $package (keys(%{$$cu_bu{$name}})) {
128 0 *{$package.'::'.$name} = $code;
129 0 add_meta($package, $name, 'kind', 'cumulative (bottom up)');
130 0 ▶ if (exists($$cu_restr{$package}{$name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cu_restr->{$package}{$name}) 0 0 0
131 0 add_meta($package, $name, 'restrict', 1);
132 }
133 }
134 }
135 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
136  
137  
138 # Returns a closure back to initialize() that is used to setup CUMULATIVE
139 # and CUMULATIVE(BOTTOM UP) methods for a particular method name.
140 3 ▶sub create_CUMULATIVE :Sub(Private)
Subroutine create_CUMULATIVE: called CC=1 SCAR=0.4
Pod undocumented
141 {
142 # $name - method name
143 # $tree - either $GBL{'tree'}{'td'} or $GBL{'tree'}{'bu'}
144 # $code_refs - hash ref by package of code refs for a particular method name
145 3 my ($name, $tree, $code_refs) = @_;
146  
147 3 ▶ return sub {
Subroutine __ANON__: called CC=14 SCAR=31.5
148 3 ▶ my $class = ref($_[0]) || $_[0];
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
300
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
149 3 ▶ if (! $class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 0 3 3
150 0 OIO::Method->die('message' => "Must call '$name' as a method");
151 }
152 3 my $list_context = wantarray;
153 3 my (@results, @classes);
154  
155 # Caller must be in class hierarchy
156 3 my $restr = $$GBL{'sub'}{'cumu'}{'restrict'};
157 3 ▶ if ($restr && exists($$restr{$class}{$name})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($restr and exists $restr->{$class}{$name}) 1 2 3
Condition66%2/3
$restr and exists $restr->{$class}{$name}
!ll&&!rl&&r
021
MC/DC50%1/2
$restr and exists $restr->{$class}{$name}
$restr exists $restr->{$class}{$name}
Truth table66%2/3
A and B
A= $restrB= exists $restr->{$class}{$name}
ABresult
0X0
100
111
158 1 my $caller = caller();
159 0 ▶ if (! ((grep { $_ eq $caller } @{$$restr{$class}{$name}}) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $caller;} @{$$restr{$class}{$name};} or $caller->isa($class) or $class->isa($caller)) 0 1 1
Condition33%2/6
grep {$_ eq $caller;} @{$$restr{$class}{$name};} or $caller->isa($class) or $class->isa($caller)
l!l&&r!l&&!r
010
grep {$_ eq $caller;} @{$$restr{$class}{$name};} or $caller->isa($class)
l!l&&r!l&&!r
001
MC/DC0%0/3
grep {$_ eq $caller;} @{$$restr{$class}{$name};} or $caller->isa($class) or $class->isa($caller)
grep {$_ eq $caller;} @{$$restr{$class}{$name};} $caller->isa($class) $class->isa($caller)
Truth table25%1/4
A or B or C
A= grep {$_ eq $caller;} @{$$restr{$class}{$name};}B= $caller->isa($class)C= $class->isa($caller)
ABCresult
1XX1
01X1
0011
0000
160 $caller->isa($class) ||
161 $class->isa($caller)))
162 {
163 0 OIO::Method->die('message' => "Can't call restricted method '$class->$name' from class '$caller'");
164 }
165 }
166  
167 # Accumulate results
168 3 foreach my $pkg (@{$$tree{$class}}) {
169 9 ▶ if (my $code = $$code_refs{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $code_refs->{$pkg}) 9 0 9
170 9 local $SIG{'__DIE__'} = 'OIO::trap';
171 9 my @args = @_;
172 9 ▶ if (defined($list_context)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $list_context) { } 9 0 9
173 9 push(@classes, $pkg);
174 9 ▶ if ($list_context) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list_context) { } 0 9 9
175 # List context
176 0 push(@results, $code->(@args));
177 } else {
178 # Scalar context
179 9 push(@results, scalar($code->(@args)));
180 }
181 } else {
182 # void context
183 0 $code->(@args);
184 }
185 }
186 }
187  
188 # Return results
189 3 ▶ if (defined($list_context)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $list_context) 3 0 3
190 3 ▶ if ($list_context) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list_context) 0 3 3
191 # List context
192 0 return (@results);
193 }
194 # Scalar context - returns object
195 3 return (Object::InsideOut::Results->new('VALUES' => \@results,
196 'CLASSES' => \@classes));
197 }
198 3 };
199 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
200  
201 } # End of package's lexical scope
202  
203  
204 1 package Object::InsideOut::Results; {
205  
206 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
207 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
208  
209 1 our $VERSION = '4.05';
210 1 $VERSION = eval $VERSION;
211  
212 1 ▶use Object::InsideOut 4.05;
Subroutine BEGIN: called CC=1 SCAR=0.0
213 1 ▶use Object::InsideOut::Metadata 4.05;
Subroutine BEGIN: called CC=1 SCAR=0.0
214  
215 1 my @VALUES :Field :Arg(VALUES);
216 1 my @CLASSES :Field :Arg(CLASSES);
217 1 my @HASHES :Field;
218  
219 0 ▶sub as_string :Stringify
Subroutine as_string: not called CC=1 SCAR=6.9
220 {
221 0 return (join('', grep(defined, @{$VALUES[${$_[0]}]})));
222 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
223  
224 0 ▶sub count :Numerify
Subroutine count: not called CC=1 SCAR=6.9
225 {
226 0 return (scalar(@{$VALUES[${$_[0]}]}));
227 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
228  
229 0 ▶sub have_any :Boolify
Subroutine have_any: not called CC=1 SCAR=6.9
230 {
231 0 return (@{$VALUES[${$_[0]}]} > 0);
232 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
233  
234 2 ▶sub values :Arrayify
Subroutine values: called CC=1 SCAR=0.0
235 {
236 2 return ($VALUES[${$_[0]}]);
237 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
238  
239 1 ▶sub as_hash :Hashify
Subroutine as_hash: called CC=2 SCAR=7.0
240 {
241 1 my $self = $_[0];
242  
243 1 ▶ if (! defined($HASHES[$$self])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $HASHES[$$self]) 1 0 1
244 1 my %hash;
245 1 @hash{@{$CLASSES[$$self]}} = @{$VALUES[$$self]};
246 1 $self->set(\@HASHES, \%hash);
247 }
248  
249 1 return ($HASHES[$$self]);
250 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
251  
252 # Our metadata
253 1 add_meta('Object::InsideOut::Results', {
254 'new' => {'hidden' => 1},
255 'create_field' => {'hidden' => 1},
256 'add_class' => {'hidden' => 1},
257 });
258  
259 } # End of package's lexical scope
260  
261  
262 # Ensure correct versioning
263 1 ▶($Object::InsideOut::VERSION eq '4.05')
Condition50%1/2
$Object::InsideOut::VERSION eq '4.05' || die("Version mismatch\n")
l!l
10
MC/DC0%0/1
$Object::InsideOut::VERSION eq '4.05' || die("Version mismatch\n")
$Object::InsideOut::VERSION eq '4.05'
Truth table50%1/2
A
A= $Object::InsideOut::VERSION eq '4.05'
Aresult
11
00
264 or die("Version mismatch\n");
265  
266 # EOF
« Object/InsideOut.pm ↑ Summary Object/InsideOut/Metadata.pm »