blib/lib/Object/InsideOut/Universal.pm

filter: Statementstmt 77.5% 83 / 107 Branchbran 58.1% 43 / 74 Conditioncond 33.3% 11 / 33 MC/DCmcdc 9.0% 2 / 22 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 60.0% 146 / 243 SCAR 51.8
CC
52
Cov
64%
__ANON__
177.7
__ANON__
10.4
BEGIN
1.0
CRAP 178.0
« blib/lib/Object/InsideOut/Metadata.pm ↑ Summary blib/lib/Object/InsideOut/Autoload.pm »
1 package Object::InsideOut; {
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶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 {
15 22 ▶ my ($thing, $method) = @_;
Subroutine __ANON__: called CC=43 SCAR=51.8
16  
17 22 ▶ return if (! defined($thing));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 0 22 22
18  
19 # Metadata call for methods
20 22 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 22 22
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 22 ▶ return if (! defined($method));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $method 0 22 22
26  
27 # First, try the original UNIVERSAL::can()
28 22 my $code;
29 22 ▶ if ($method =~ /^SUPER::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method =~ /^SUPER::/) { } 1 21 22
30 # Superclass WRT caller
31 1 my $caller = caller();
32 1 eval { $code = $thing->Object::InsideOut::SUPER::can($caller.'::'.$method) };
33 } else {
34 21 eval { $code = $thing->Object::InsideOut::SUPER::can($method) };
35 }
36 22 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 8 14 22
37 8 return ($code);
38 }
39  
40 # Handle various calling methods
41 14 my ($class, $super);
42 14 ▶ if ($method !~ /::/) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $method =~ /::/) { } 13 1 14
elsif (not $method =~ /SUPER::/) { } 0 1 1
elsif ($method =~ /^SUPER::/) { } 1 0 1
43 # Ordinary method check
44 # $obj->can('x');
45 13 ▶ $class = ref($thing) || $thing;
Condition66%2/3
ref $thing || $thing
l!l&&r!l&&!r
580
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 1 $class = caller();
56 1 $method =~ s/SUPER:://;
57 1 $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 14 my $heritage = $$GBL{'heritage'};
67 14 my $automethods = $$GBL{'sub'}{'auto'};
68  
69 # Next, check with heritage objects and Automethods
70 14 my ($code_type, $code_dir, %code_refs);
71 14 foreach my $pkg (@{$$GBL{'tree'}{'bu'}{$class}}) {
72 # Skip self's class if SUPER
73 28 ▶ if ($super && $class eq $pkg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($super and $class eq $pkg) 1 27 28
Condition100%3/3
$super and $class eq $pkg
!ll&&!rl&&r
2521
MC/DC100%2/2
$super and $class eq $pkg
$super $class eq $pkg
Truth table100%3/3
A and B
A= $superB= $class eq $pkg
ABresult
0X0
100
111
74 1 next;
75 }
76  
77 # Check heritage
78 27 ▶ if (exists($$heritage{$pkg})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $heritage->{$pkg}) 4 23 27
79 6 ▶ 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 23 ▶ if (my $automethod = $$automethods{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $automethod = $automethods->{$pkg}) 14 9 23
89 # Call the Automethod to get a code ref
90 14 local $CALLER::_ = $_;
91 14 local $_ = $method;
92 14 local $SIG{'__DIE__'} = 'OIO::trap';
93 14 ▶ if (my ($code, $ctype) = $automethod->($thing)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &$automethod($thing)) 12 2 14
94 12 ▶ if (ref($code) ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $code ne "CODE") 0 12 12
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 12 ▶ if (defined($ctype)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ctype) 3 9 12
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 9 ▶ if ($code_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_type) 0 9 9
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 9 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 {
174 123 ▶ my ($thing, $type) = @_;
Subroutine __ANON__: called CC=10 SCAR=23.4
175  
176 123 ▶ return ('') if (! defined($thing));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 0 123 123
177  
178 # Metadata call for classes
179 123 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 123 123
180 0 return Object::InsideOut::meta($thing)->get_classes();
181 }
182  
183 # Workaround for Perl bug #47233
184 123 ▶ return ('') if (! defined($type));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 123 123
185  
186 # Try original UNIVERSAL::isa()
187 123 ▶ 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 84 123
188 39 return ($isa);
189 }
190  
191 # Next, check heritage
192 84 ▶ foreach my $pkg (@{$$GBL{'tree'}{'bu'}{ref($thing) || $thing}}) {
Condition66%2/3
ref $thing || $thing
l!l&&r!l&&!r
5790
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 119 ▶ if (exists($$GBL{'heritage'}{$pkg})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $GBL->{"heritage"}{$pkg}) 28 91 119
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 72 return (''); # Isn't
203 };
204  
205  
206 # Stub ourself out
207 ▶ *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 6 ▶($Object::InsideOut::VERSION eq '4.04')
Branch: 1 branch
BranchTrueFalseTotal
$VERSION eq "4.04" or die "Version mismatch\n" 0 6 6
215 or die("Version mismatch\n");
216  
217 # EOF
« blib/lib/Object/InsideOut/Metadata.pm ↑ Summary blib/lib/Object/InsideOut/Autoload.pm »