Object/InsideOut/Autoload.pm

filter: Statementstmt 76.9% 70 / 91 Branchbran 53.7% 29 / 54 Conditioncond 20.6% 6 / 29 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 55.3% 109 / 197 CC 41 SCAR 50.5
CC
41
Cov
60%
__ANON__
167.7
BEGIN
1.0
BEGIN
1.0
CRAP 156.3
« Object/InsideOut/Util.pm ↑ Summary Object/InsideOut/Foreign.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 # Handles :Automethods and foreign inheritance
8 sub AUTOLOAD
9 {
10 my ($GBL, @args) = @_;
11 push(@{$$GBL{'export'}}, 'AUTOLOAD');
12 $$GBL{'init'} = 1;
13  
14 *Object::InsideOut::AUTOLOAD = sub
15 12 ▶ {
Subroutine __ANON__: called CC=41 SCAR=51.2
16 12 my $thing = $_[0];
17  
18 # Extract the class and method names from the fully-qualified name
19 12 my ($class, $method) = our $AUTOLOAD =~ /(.*)::(.*)/;
20  
21 # Handle superclass calls
22 12 my $super;
23 12 ▶ if ($class =~ /::SUPER$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /::SUPER$/) 0 12 12
24 0 $class =~ s/::SUPER//;
25 0 $super = 1;
26 }
27  
28 12 my $heritage = $$GBL{'heritage'};
29 12 my $automethods = $$GBL{'sub'}{'auto'};
30  
31 # Find a something to handle the method call
32 12 my ($code_type, $code_dir, %code_refs);
33 12 foreach my $pkg (@{$$GBL{'tree'}{'bu'}{$class}}) {
34 # Skip self's class if SUPER
35 23 ▶ if ($super && $class eq $pkg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($super and $class eq $pkg) 0 23 23
Condition33%1/3
$super and $class eq $pkg
!ll&&!rl&&r
2300
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
36 0 next;
37 }
38  
39 # Check with heritage objects/classes
40 23 ▶ if (exists($$heritage{$pkg})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $heritage->{$pkg}) 9 14 23
41 9 my $objects = $$heritage{$pkg}{'obj'};
42 9 my $classes = $$heritage{$pkg}{'cl'};
43 9 ▶ if (Scalar::Util::blessed($thing)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($thing)) { } 8 1 9
44 8 ▶ if (exists($$objects{$$thing})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$objects{$$thing}) { } 4 4 8
45 # Check objects
46 4 foreach my $obj (@{$$objects{$$thing}}) {
47 4 ▶ if (my $code = $obj->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $obj->can($method)) 4 0 4
48 4 shift;
49 4 unshift(@_, $obj);
50 4 goto $code;
51 }
52 }
53 } else {
54 # Check classes
55 4 foreach my $pkg (keys(%{$classes})) {
56 4 ▶ if (my $code = $pkg->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $pkg->can($method)) 4 0 4
57 4 @_ = @_; # Perl 5.8.5 bug workaround
58 4 goto $code;
59 }
60 }
61 }
62 } else {
63 # Check classes
64 1 foreach my $pkg (keys(%{$classes})) {
65 1 ▶ if (my $code = $pkg->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $pkg->can($method)) 1 0 1
66 1 shift;
67 1 unshift(@_, $pkg);
68 1 goto $code;
69 }
70 }
71 }
72 }
73  
74 # Check with Automethod
75 14 ▶ if (my $automethod = $$automethods{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $automethod = $automethods->{$pkg}) 4 10 14
76 # Call the Automethod to get a code ref
77 4 local $CALLER::_ = $_;
78 4 local $_ = $method;
79 4 local $SIG{'__DIE__'} = 'OIO::trap';
80 4 ▶ if (my ($code, $ctype) = $automethod->(@_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &$automethod(@_)) 4 0 4
81 4 ▶ if (ref($code) ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $code ne "CODE") 0 4 4
82 # Delete defective automethod
83 0 delete($$automethods{$pkg});
84 # Not a code ref
85 0 OIO::Code->die(
86 'message' => ':Automethod did not return a code ref',
87 'Info' => "NOTICE: The defective :Automethod in package '$pkg' has been DELETED!",
88 'Code' => ":Automethod in package '$pkg' invoked for method '$method'");
89 }
90  
91 4 ▶ if (defined($ctype)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ctype) 3 1 4
92 3 my ($type, $dir) = $ctype =~ /(\w+)(?:[(]\s*(.*)\s*[)])?/;
93 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
94 3 ▶ if ($code_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_type) { } 2 1 3
95 2 $type = ':Cumulative';
96 2 ▶ $dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down';
Branch: 1 branch
BranchTrueFalseTotal
$dir && $dir =~ /BOT/i ? : 2 0 2
Condition33%1/3
$dir and $dir =~ /BOT/i
!ll&&!rl&&r
002
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
97 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
98 # Mixed types
99 0 my ($pkg2) = keys(%code_refs);
100 0 OIO::Code->die(
101 'message' => 'Inconsistent code types returned by :Automethods',
102 'Info' => "Class '$pkg' returned type $type($dir), and class '$pkg2' returned type $code_type($code_dir)");
103 }
104 } else {
105 1 $code_type = ':Cumulative';
106 1 ▶ $code_dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down';
Branch: 1 branch
BranchTrueFalseTotal
$dir && $dir =~ /BOT/i ? : 1 0 1
Condition33%1/3
$dir and $dir =~ /BOT/i
!ll&&!rl&&r
001
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 }
108 3 $code_refs{$pkg} = $code;
109 3 next;
110 }
111 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
112 0 ▶ if ($code_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_type) { } 0 0 0
113 0 $type = ':Chained';
114 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
115 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
116 # Mixed types
117 0 my ($pkg2) = keys(%code_refs);
118 0 OIO::Code->die(
119 'message' => 'Inconsistent code types returned by :Automethods',
120 'Info' => "Class '$pkg' returned type $type($dir), and class '$pkg2' returned type $code_type($code_dir)");
121 }
122 } else {
123 0 $code_type = ':Chained';
124 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
125 }
126 0 $code_refs{$pkg} = $code;
127 0 next;
128 }
129  
130 # Unknown automethod code type
131 OIO::Code->die(
132 0 'message' => "Unknown :Automethod code type: $ctype",
133 'Info' => ":Automethod in package '$pkg' invoked for method '$method'");
134 }
135  
136 1 ▶ if ($code_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_type) 0 1 1
137 # Mixed types
138 0 my ($pkg2) = keys(%code_refs);
139 0 OIO::Code->die(
140 'message' => 'Inconsistent code types returned by :Automethods',
141 'Info' => "Class '$pkg' returned an 'execute immediately' type, and class '$pkg2' returned type $code_type($code_dir)");
142 }
143  
144 # Just a one-shot - execute it
145 1 @_ = @_; # Perl 5.8.5 bug workaround
146 1 goto $code;
147 }
148 }
149 }
150  
151 2 ▶ if ($code_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_type) 1 1 2
152 1 ▶ my $tree = ($code_dir eq 'bottom up') ? $$GBL{'tree'}{'bu'} : $$GBL{'tree'}{'td'};
Branch: 1 branch
BranchTrueFalseTotal
$code_dir eq 'bottom up' ? : 1 0 1
153 1 ▶ my $code = ($code_type eq ':Cumulative')
Branch: 1 branch
BranchTrueFalseTotal
$code_type eq ':Cumulative' ? : 1 0 1
154 ? create_CUMULATIVE($method, $tree, \%code_refs)
155 : create_CHAINED($method, $tree, \%code_refs);
156 1 @_ = @_; # Perl 5.8.5 bug workaround
157 1 goto $code;
158 }
159  
160 # Failed to AUTOLOAD
161 1 ▶ my $type = ref($thing) ? 'object' : 'class';
Branch: 1 branch
BranchTrueFalseTotal
ref $thing ? : 1 0 1
162 1 OIO::Method->die('message' => qq/Can't locate $type method "$method" via package "$class"/);
163 };
164  
165  
166 # Do the original call
167 @_ = @args;
168 goto &Object::InsideOut::AUTOLOAD;
169 }
170  
171 } # End of package's lexical scope
172  
173  
174 # Ensure correct versioning
175 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
176 or die("Version mismatch\n");
177  
178 # EOF
« Object/InsideOut/Util.pm ↑ Summary Object/InsideOut/Foreign.pm »