Object/InsideOut/Universal.pm

filter: Statementstmt 69.1% 74 / 107 Branchbran 47.2% 34 / 72 Conditioncond 28.5% 10 / 35 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 51.2% 125 / 244 CC 52 SCAR 54.7
CC
52
Cov
55%
__ANON__
317.4
__ANON__
10.4
BEGIN
1.0
CRAP 237.2
« Object/InsideOut/lvalue.pm ↑ Summary Object/InsideOut/Util.pm »
1 package Object::InsideOut; {
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # Install versions of UNIVERSAL::can/isa that understands :Automethod and
8 # foreign inheritance
9 sub install_UNIVERSAL
10 {
11 my ($GBL) = @_;
12  
13 *Object::InsideOut::can = sub
14 12 ▶ {
Subroutine __ANON__: called CC=43 SCAR=57.6
15 12 my ($thing, $method) = @_;
16  
17 12 ▶ return if (! defined($thing));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 0 12 12
18  
19 # Metadata call for methods
20 12 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 12 12
21 0 my $meths = Object::InsideOut::meta(shift)->get_methods();
22 0 ▶ return (wantarray()) ? (keys(%$meths)) : [ keys(%$meths) ];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
23 }
24  
25 12 ▶ return if (! defined($method));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $method 0 12 12
26  
27 # First, try the original UNIVERSAL::can()
28 12 my $code;
29 12 ▶ if ($method =~ /^SUPER::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method =~ /^SUPER::/) { } 0 12 12
30 # Superclass WRT caller
31 0 my $caller = caller();
32 0 eval { $code = $thing->Object::InsideOut::SUPER::can($caller.'::'.$method) };
33 } else {
34 12 eval { $code = $thing->Object::InsideOut::SUPER::can($method) };
35 }
36 12 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 7 5 12
37 7 return ($code);
38 }
39  
40 # Handle various calling methods
41 5 my ($class, $super);
42 5 ▶ if ($method !~ /::/) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $method =~ /::/) { } 5 0 5
elsif (not $method =~ /SUPER::/) { } 0 0 0
elsif ($method =~ /^SUPER::/) { } 0 0 0
43 # Ordinary method check
44 # $obj->can('x');
45 5 ▶ $class = ref($thing) || $thing;
Condition66%2/3
ref $thing || $thing
l!l&&r!l&&!r
320
MC/DC0%0/2
ref $thing || $thing
ref $thing $thing
Truth table66%2/3
A || B
A= ref $thingB= $thing
ABresult
1X1
011
000
46  
47 } elsif ($method !~ /SUPER::/) {
48 # Fully-qualified method check
49 # $obj->can('FOO::x');
50 0 ($class, $method) = $method =~ /^(.+)::([^:]+)$/;
51  
52 } elsif ($method =~ /^SUPER::/) {
53 # Superclass method check
54 # $obj->can('SUPER::x');
55 0 $class = caller();
56 0 $method =~ s/SUPER:://;
57 0 $super = 1;
58  
59 } else {
60 # Qualified superclass method check
61 # $obj->can('Foo::SUPER::x');
62 0 ($class, $method) = $method =~ /^(.+)::SUPER::([^:]+)$/;
63 0 $super = 1;
64 }
65  
66 5 my $heritage = $$GBL{'heritage'};
67 5 my $automethods = $$GBL{'sub'}{'auto'};
68  
69 # Next, check with heritage objects and Automethods
70 5 my ($code_type, $code_dir, %code_refs);
71 5 foreach my $pkg (@{$$GBL{'tree'}{'bu'}{$class}}) {
72 # Skip self's class if SUPER
73 11 ▶ if ($super && $class eq $pkg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($super and $class eq $pkg) 0 11 11
Condition33%1/3
$super and $class eq $pkg
!ll&&!rl&&r
1100
MC/DC0%0/2
$super and $class eq $pkg
$super $class eq $pkg
Truth table33%1/3
A and B
A= $superB= $class eq $pkg
ABresult
0X0
100
111
74 0 next;
75 }
76  
77 # Check heritage
78 11 ▶ if (exists($$heritage{$pkg})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $heritage->{$pkg}) 4 7 11
79 5 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 4 foreach my $pkg2 (keys(%{$$heritage{$pkg}{'cl'}})) {
81 4 ▶ if ($code = $pkg2->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code = $pkg2->can($method)) 4 0 4
82 4 return ($code);
83 }
84 }
85 }
86  
87 # Check with the Automethods
88 7 ▶ if (my $automethod = $$automethods{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $automethod = $automethods->{$pkg}) 3 4 7
89 # Call the Automethod to get a code ref
90 3 local $CALLER::_ = $_;
91 3 local $_ = $method;
92 3 local $SIG{'__DIE__'} = 'OIO::trap';
93 3 ▶ if (my ($code, $ctype) = $automethod->($thing)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &$automethod($thing)) 3 0 3
94 3 ▶ if (ref($code) ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $code ne "CODE") 0 3 3
95 # Not a code ref
96 0 OIO::Code->die(
97 'message' => ':Automethod did not return a code ref',
98 'Info' => ":Automethod in package '$pkg' invoked for method '$method'");
99 }
100  
101 3 ▶ if (defined($ctype)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ctype) 3 0 3
102 3 my ($type, $dir) = $ctype =~ /(\w+)(?:[(]\s*(.*)\s*[)])?/;
103 3 ▶ if ($type && $type =~ /CUM/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and $type =~ /CUM/i) 3 0 3
Condition33%1/3
$type and $type =~ /CUM/i
!ll&&!rl&&r
003
MC/DC0%0/2
$type and $type =~ /CUM/i
$type $type =~ /CUM/i
Truth table33%1/3
A and B
A= $typeB= $type =~ /CUM/i
ABresult
0X0
100
111
104 3 ▶ if ($code_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_type) { } 2 1 3
105 2 $type = ':Cumulative';
106 2 ▶ $dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down';
Branch: 1 branch
BranchTrueFalseTotal
$dir && $dir =~ /BOT/i ? : 0 2 2
Condition33%1/3
$dir and $dir =~ /BOT/i
!ll&&!rl&&r
200
MC/DC0%0/2
$dir and $dir =~ /BOT/i
$dir $dir =~ /BOT/i
Truth table33%1/3
A and B
A= $dirB= $dir =~ /BOT/i
ABresult
0X0
100
111
107 2 ▶ if ($code_type ne $type || $code_dir ne $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_type ne $type or $code_dir ne $dir) 0 2 2
Condition33%1/3
$code_type ne $type or $code_dir ne $dir
l!l&&r!l&&!r
002
MC/DC0%0/2
$code_type ne $type or $code_dir ne $dir
$code_type ne $type $code_dir ne $dir
Truth table33%1/3
A or B
A= $code_type ne $typeB= $code_dir ne $dir
ABresult
1X1
011
000
108 # Mixed types
109 0 my ($pkg2) = keys(%code_refs);
110 0 OIO::Code->die(
111 'message' => 'Inconsistent code types returned by :Automethods',
112 'Info' => "Class '$pkg' returned type $type($dir), and class '$pkg2' returned type $code_type($code_dir)");
113 }
114 } else {
115 1 $code_type = ':Cumulative';
116 1 ▶ $code_dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down';
Branch: 1 branch
BranchTrueFalseTotal
$dir && $dir =~ /BOT/i ? : 0 1 1
Condition33%1/3
$dir and $dir =~ /BOT/i
!ll&&!rl&&r
100
MC/DC0%0/2
$dir and $dir =~ /BOT/i
$dir $dir =~ /BOT/i
Truth table33%1/3
A and B
A= $dirB= $dir =~ /BOT/i
ABresult
0X0
100
111
117 }
118 3 $code_refs{$pkg} = $code;
119 3 next;
120 }
121 0 ▶ if ($type && $type =~ /CHA/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and $type =~ /CHA/i) 0 0 0
Condition0%0/3
$type and $type =~ /CHA/i
!ll&&!rl&&r
000
MC/DC0%0/2
$type and $type =~ /CHA/i
$type $type =~ /CHA/i
Truth table0%0/3
A and B
A= $typeB= $type =~ /CHA/i
ABresult
0X0
100
111
122 0 ▶ if ($code_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_type) { } 0 0 0
123 0 $type = ':Chained';
124 0 ▶ $dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down';
Branch: 1 branch
BranchTrueFalseTotal
$dir && $dir =~ /BOT/i ? : 0 0 0
Condition0%0/3
$dir and $dir =~ /BOT/i
!ll&&!rl&&r
000
MC/DC0%0/2
$dir and $dir =~ /BOT/i
$dir $dir =~ /BOT/i
Truth table0%0/3
A and B
A= $dirB= $dir =~ /BOT/i
ABresult
0X0
100
111
125 0 ▶ if ($code_type ne $type || $code_dir ne $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_type ne $type or $code_dir ne $dir) 0 0 0
Condition0%0/3
$code_type ne $type or $code_dir ne $dir
l!l&&r!l&&!r
000
MC/DC0%0/2
$code_type ne $type or $code_dir ne $dir
$code_type ne $type $code_dir ne $dir
Truth table0%0/3
A or B
A= $code_type ne $typeB= $code_dir ne $dir
ABresult
1X1
011
000
126 # Mixed types
127 0 my ($pkg2) = keys(%code_refs);
128 0 OIO::Code->die(
129 'message' => 'Inconsistent code types returned by :Automethods',
130 'Info' => "Class '$pkg' returned type $type($dir), and class '$pkg2' returned type $code_type($code_dir)");
131 }
132 } else {
133 0 $code_type = ':Chained';
134 0 ▶ $code_dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down';
Branch: 1 branch
BranchTrueFalseTotal
$dir && $dir =~ /BOT/i ? : 0 0 0
Condition0%0/3
$dir and $dir =~ /BOT/i
!ll&&!rl&&r
000
MC/DC0%0/2
$dir and $dir =~ /BOT/i
$dir $dir =~ /BOT/i
Truth table0%0/3
A and B
A= $dirB= $dir =~ /BOT/i
ABresult
0X0
100
111
135 }
136 0 $code_refs{$pkg} = $code;
137 0 next;
138 }
139  
140 # Unknown automethod code type
141 OIO::Code->die(
142 0 'message' => "Unknown :Automethod code type: $ctype",
143 'Info' => ":Automethod in package '$pkg' invoked for method '$method'");
144 }
145  
146 0 ▶ if ($code_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_type) 0 0 0
147 # Mixed types
148 0 my ($pkg2) = keys(%code_refs);
149 0 OIO::Code->die(
150 'message' => 'Inconsistent code types returned by :Automethods',
151 'Info' => "Class '$pkg' returned an 'execute immediately' type, and class '$pkg2' returned type $code_type($code_dir)");
152 }
153  
154 # Just a one-shot - return it
155 0 return ($code);
156 }
157 }
158 }
159  
160 1 ▶ if ($code_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_type) 1 0 1
161 1 ▶ my $tree = ($code_dir eq 'bottom up') ? $$GBL{'tree'}{'bu'} : $$GBL{'tree'}{'td'};
Branch: 1 branch
BranchTrueFalseTotal
$code_dir eq 'bottom up' ? : 0 1 1
162 1 ▶ $code = ($code_type eq ':Cumulative')
Branch: 1 branch
BranchTrueFalseTotal
$code_type eq ':Cumulative' ? : 1 0 1
163 ? create_CUMULATIVE($method, $tree, \%code_refs)
164 : create_CHAINED($method, $tree, \%code_refs);
165 1 return ($code);
166 }
167  
168 0 return; # Can't
169 };
170  
171  
172 *Object::InsideOut::isa = sub
173 95 ▶ {
Subroutine __ANON__: called CC=10 SCAR=23.4
174 95 my ($thing, $type) = @_;
175  
176 95 ▶ return ('') if (! defined($thing));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 0 95 95
177  
178 # Metadata call for classes
179 95 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 95 95
180 0 return Object::InsideOut::meta($thing)->get_classes();
181 }
182  
183 # Workaround for Perl bug #47233
184 95 ▶ return ('') if (! defined($type));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 95 95
185  
186 # Try original UNIVERSAL::isa()
187 95 ▶ if (my $isa = eval { $thing->Object::InsideOut::SUPER::isa($type) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $isa = eval { do { $thing->Object::InsideOut::SUPER::isa($type) } }) 39 56 95
188 39 return ($isa);
189 }
190  
191 # Next, check heritage
192 56 ▶ foreach my $pkg (@{$$GBL{'tree'}{'bu'}{ref($thing) || $thing}}) {
Condition66%2/3
ref $thing || $thing
l!l&&r!l&&!r
4520
MC/DC0%0/2
ref $thing || $thing
ref $thing $thing
Truth table66%2/3
A || B
A= ref $thingB= $thing
ABresult
1X1
011
000
193 70 ▶ if (exists($$GBL{'heritage'}{$pkg})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GBL->{"heritage"}{$pkg}) 28 42 70
194 28 foreach my $pkg (keys(%{$$GBL{'heritage'}{$pkg}{'cl'}})) {
195 28 ▶ if (my $isa = $pkg->isa($type)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $isa = $pkg->isa($type)) 12 16 28
196 12 return ($isa);
197 }
198 }
199 }
200 }
201  
202 44 return (''); # Isn't
203 };
204  
205  
206 # Stub ourself out
207 6 ▶ *Object::InsideOut::install_UNIVERSAL = sub { };
Subroutine __ANON__: called CC=1 SCAR=0.0
208 }
209  
210 } # End of package's lexical scope
211  
212  
213 # Ensure correct versioning
214 5 ▶($Object::InsideOut::VERSION eq '4.05')
Condition50%1/2
$VERSION eq '4.05' || die("Version mismatch\n")
l!l
50
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
215 or die("Version mismatch\n");
216  
217 # EOF
« Object/InsideOut/lvalue.pm ↑ Summary Object/InsideOut/Util.pm »