Object/InsideOut/Chained.pm

filter: Statementstmt 92.9% 131 / 141 Branchbran 82.5% 33 / 40 Conditioncond 67.7% 21 / 31 MC/DCmcdc 33.3% 6 / 18 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 83.0% 201 / 242 CC 43 SCAR 32.8
CC
43
Cov
87%
generate_CHAINED
37.5
__ANON__
10.1
create_CHAINED
1.0
CRAP 26.6
« Object/InsideOut/Dynamic.pm ↑ Summary Object/InsideOut/Dump.pm »
1 package Object::InsideOut; {
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 my $GBL = {};
8  
9 4 ▶sub generate_CHAINED :Sub(Private)
Subroutine generate_CHAINED: called CC=34 SCAR=36.2
Pod undocumented
10 {
11 4 ($GBL) = @_;
12 4 my $g_ch = $$GBL{'sub'}{'chain'};
13 4 ▶ my $chain_td = $$g_ch{'new'}{'td'} || [];
Condition100%2/2
$g_ch->{'new'}{'td'} || []
l!l
31
MC/DC100%1/1
$g_ch->{'new'}{'td'} || []
$g_ch->{'new'}{'td'}
Truth table100%2/2
A
A= $g_ch->{'new'}{'td'}
Aresult
11
00
14 4 ▶ my $chain_bu = $$g_ch{'new'}{'bu'} || [];
Condition100%2/2
$g_ch->{'new'}{'bu'} || []
l!l
22
MC/DC100%1/1
$g_ch->{'new'}{'bu'} || []
$g_ch->{'new'}{'bu'}
Truth table100%2/2
A
A= $g_ch->{'new'}{'bu'}
Aresult
11
00
15 4 delete($$g_ch{'new'});
16 4 ▶ if (! exists($$g_ch{'td'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $g_ch->{"td"}) 4 0 4
17 4 $$GBL{'sub'}{'chain'} = {
18 td => {}, # 'Top down'
19 bu => {}, # 'Bottom up'
20 restrict => {}, # :Restricted
21 };
22 4 $g_ch = $$GBL{'sub'}{'chain'};
23 }
24 4 my $ch_td = $$g_ch{'td'};
25 4 my $ch_bu = $$g_ch{'bu'};
26 4 my $ch_restr = $$g_ch{'restrict'};
27  
28 # Get names for :CHAINED methods
29 4 my (%chain_loc);
30 4 ▶ while (my $info = shift(@{$chain_td})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = shift @{$chain_td;}) 18 4 22
31 18 ▶ $$info{'name'} ||= sub_name($$info{'code'}, ':CHAINED', $$info{'loc'});
Condition66%2/3
$info->{"name"} ||= sub_name($info->{"code"}, ":CHAINED", $info->{"loc"})
l!l&&r!l&&!r
1260
MC/DC0%0/2
$info->{"name"} ||= sub_name($info->{"code"}, ":CHAINED", $info->{"loc"})
$info->{"name"} sub_name($info->{"code"}, ":CHAINED", $info->{"loc"})
Truth table66%2/3
A ||= B
A= $info->{"name"}B= sub_name($info->{"code"}, ":CHAINED", $info->{"loc"})
ABresult
1X1
011
000
32 18 my $package = $$info{'pkg'};
33 18 my $name = $$info{'name'};
34  
35 18 $chain_loc{$name}{$package} = $$info{'loc'};
36  
37 18 $$ch_td{$name}{$package} = $$info{'wrap'};
38 18 ▶ if (exists($$info{'exempt'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{"exempt"}) 2 16 18
39 2 push(@{$$ch_restr{$package}{$name}},
40 2 ▶ sort grep {$_} split(/[,'\s]+/, $$info{'exempt'} || ''));
Condition50%1/2
$info->{'exempt'} || ''
l!l
20
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 :CHAINED(BOTTOM UP) methods
45 4 ▶ while (my $info = shift(@{$chain_bu})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = shift @{$chain_bu;}) 9 4 13
46 9 ▶ $$info{'name'} ||= sub_name($$info{'code'}, ':CHAINED(BOTTOM UP)', $$info{'loc'});
Condition66%2/3
$info->{"name"} ||= sub_name($info->{"code"}, ":CHAINED(BOTTOM UP)", $info->{"loc"})
l!l&&r!l&&!r
360
MC/DC0%0/2
$info->{"name"} ||= sub_name($info->{"code"}, ":CHAINED(BOTTOM UP)", $info->{"loc"})
$info->{"name"} sub_name($info->{"code"}, ":CHAINED(BOTTOM UP)", $info->{"loc"})
Truth table66%2/3
A ||= B
A= $info->{"name"}B= sub_name($info->{"code"}, ":CHAINED(BOTTOM UP)", $info->{"loc"})
ABresult
1X1
011
000
47 9 my $package = $$info{'pkg'};
48 9 my $name = $$info{'name'};
49  
50 # Check for conflicting definitions of 'name'
51 9 ▶ if ($$ch_td{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch_td->{$name}) 0 9 9
52 0 foreach my $other_package (keys(%{$$ch_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) = @{$chain_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 chained method '$name'",
61 'Info' => "Declared as :CHAINED in class '$pkg' (file '$file', line $line), but declared as :CHAINED(BOTTOM UP) in class '$pkg2' (file '$file2' line $line2)");
62 }
63 }
64 }
65  
66 9 $$ch_bu{$name}{$package} = $$info{'wrap'};
67 9 ▶ if (exists($$info{'exempt'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{"exempt"}) 3 6 9
68 3 push(@{$$ch_restr{$package}{$name}},
69 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
70 }
71 }
72  
73 # Propagate restrictions
74 4 my $reapply = 1;
75 4 my $trees = $$GBL{'tree'}{'td'};
76 4 ▶ while ($reapply) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reapply) 5 4 9
77 5 $reapply = 0;
78 5 foreach my $pkg (keys(%{$ch_restr})) {
79 12 foreach my $class (keys(%{$trees})) {
80 84 ▶ next if (! grep { $_ eq $pkg } @{$$trees{$class}});
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $pkg;} @{$$trees{$class};} 47 37 84
81 37 foreach my $p (@{$$trees{$class}}) {
82 157 foreach my $n (keys(%{$$ch_restr{$pkg}})) {
83 157 ▶ if (exists($$ch_restr{$p}{$n})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ch_restr->{$p}{$n}) { } 152 5 157
84 152 ▶ next if ($$ch_restr{$p}{$n} == $$ch_restr{$pkg}{$n});
Branch: 1 branch
BranchTrueFalseTotal
if $ch_restr->{$p}{$n} == $ch_restr->{$pkg}{$n} 149 3 152
85 3 my $equal = (@{$$ch_restr{$p}{$n}} == @{$$ch_restr{$pkg}{$n}});
86 3 ▶ if ($equal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($equal) 3 0 3
87 3 for (1..@{$$ch_restr{$p}{$n}}) {
88 1 ▶ if ($$ch_restr{$pkg}{$n}[$_-1] ne $$ch_restr{$p}{$n}[$_-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch_restr->{$pkg}{$n}[$_ - 1] ne $ch_restr->{$p}{$n}[$_ - 1]) 1 0 1
89 1 $equal = 0;
90 1 last;
91 }
92 }
93 }
94 3 ▶ if (! $equal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($equal) 1 2 3
95 1 my %restr = map { $_ => 1 } @{$$ch_restr{$p}{$n}}, @{$$ch_restr{$pkg}{$n}};
96 1 $$ch_restr{$pkg}{$n} = [ sort(keys(%restr)) ];
97 1 $reapply = 1;
98 }
99 } else {
100 5 $reapply = 1;
101 }
102 8 $$ch_restr{$p}{$n} = $$ch_restr{$pkg}{$n};
103 }
104 }
105 }
106 }
107 }
108  
109 4 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
110 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112 # Implement :CHAINED methods
113 4 foreach my $name (keys(%{$ch_td})) {
114 3 my $code = create_CHAINED($name, $trees, $$ch_td{$name});
115 3 foreach my $package (keys(%{$$ch_td{$name}})) {
116 18 *{$package.'::'.$name} = $code;
117 18 add_meta($package, $name, 'kind', 'chained');
118 18 ▶ if (exists($$ch_restr{$package}{$name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ch_restr->{$package}{$name}) 6 12 18
119 6 add_meta($package, $name, 'restricted', 1);
120 }
121 }
122 }
123  
124 # Implement :CHAINED(BOTTOM UP) methods
125 4 foreach my $name (keys(%{$ch_bu})) {
126 2 my $code = create_CHAINED($name, $$GBL{'tree'}{'bu'}, $$ch_bu{$name});
127 2 foreach my $package (keys(%{$$ch_bu{$name}})) {
128 9 *{$package.'::'.$name} = $code;
129 9 add_meta($package, $name, 'kind', 'chained (bottom up)');
130 9 ▶ if (exists($$ch_restr{$package}{$name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ch_restr->{$package}{$name}) 3 6 9
131 3 add_meta($package, $name, 'restricted', 1);
132 }
133 }
134 }
135 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
136  
137  
138 # Returns a closure back to initialize() that is used to setup CHAINED
139 # and CHAINED(BOTTOM UP) methods for a particular method name.
140 5 ▶sub create_CHAINED :Sub(Private)
Subroutine create_CHAINED: called CC=1 SCAR=0.0
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 5 my ($name, $tree, $code_refs) = @_;
146  
147 10 ▶ return sub {
Subroutine __ANON__: called CC=10 SCAR=23.1
148 10 my $thing = shift;
149 10 ▶ my $class = ref($thing) || $thing;
Condition66%2/3
ref $thing || $thing
l!l&&r!l&&!r
730
MC/DC0%0/2
ref $thing || $thing
ref $thing $thing
Truth table66%2/3
A || B
A= ref $thingB= $thing
ABresult
1X1
011
000
150 10 ▶ if (! $class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 0 10 10
151 0 OIO::Method->die('message' => "Must call '$name' as a method");
152 }
153 10 my @args = @_;
154  
155 # Caller must be in class hierarchy
156 10 my $restr = $$GBL{'sub'}{'chain'}{'restrict'};
157 10 ▶ if ($restr && exists($$restr{$class}{$name})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($restr and exists $restr->{$class}{$name}) 7 3 10
Condition66%2/3
$restr and exists $restr->{$class}{$name}
!ll&&!rl&&r
037
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 7 my $caller = caller();
159 7 ▶ 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)) 1 6 7
Condition100%6/6
grep {$_ eq $caller;} @{$$restr{$class}{$name};} or $caller->isa($class) or $class->isa($caller)
l!l&&r!l&&!r
511
grep {$_ eq $caller;} @{$$restr{$class}{$name};} or $caller->isa($class)
l!l&&r!l&&!r
142
MC/DC100%3/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 table100%4/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 1 OIO::Method->die('message' => "Can't call restricted method '$class->$name' from class '$caller'");
164 }
165 }
166  
167 # Chain results together
168 9 foreach my $pkg (@{$$tree{$class}}) {
169 44 ▶ if (my $code = $$code_refs{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $code_refs->{$pkg}) 39 5 44
170 39 local $SIG{'__DIE__'} = 'OIO::trap';
171 39 @args = $thing->$code(@args);
172 }
173 }
174  
175 # Return results
176 9 return (@args);
177 5 };
178 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
179  
180 } # End of package's lexical scope
181  
182  
183 # Ensure correct versioning
184 4 ▶($Object::InsideOut::VERSION eq '4.05')
Condition50%1/2
$VERSION eq '4.05' || die("Version mismatch\n")
l!l
40
MC/DC0%0/1
$VERSION eq '4.05' || die("Version mismatch\n")
$VERSION eq '4.05'
Truth table50%1/2
A
A= $VERSION eq '4.05'
Aresult
11
00
185 or die("Version mismatch\n");
186  
187 # EOF
« Object/InsideOut/Dynamic.pm ↑ Summary Object/InsideOut/Dump.pm »