line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Object::InsideOut; { |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
39
|
use strict; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
250
|
|
4
|
8
|
|
|
8
|
|
27
|
use warnings; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
201
|
|
5
|
8
|
|
|
8
|
|
25
|
no warnings 'redefine'; |
|
8
|
|
|
|
|
48
|
|
|
8
|
|
|
|
|
2614
|
|
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
|
27
|
|
|
27
|
|
8606
|
my ($thing, $method) = @_; |
16
|
|
|
|
|
|
|
|
17
|
27
|
50
|
|
|
|
65
|
return if (! defined($thing)); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Metadata call for methods |
20
|
27
|
100
|
|
|
|
64
|
if (@_ == 1) { |
21
|
4
|
|
|
|
|
10
|
my $meths = Object::InsideOut::meta(shift)->get_methods(); |
22
|
4
|
100
|
|
|
|
11
|
return (wantarray()) ? (keys(%$meths)) : [ keys(%$meths) ]; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
23
|
50
|
|
|
|
44
|
return if (! defined($method)); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# First, try the original UNIVERSAL::can() |
28
|
23
|
|
|
|
|
20
|
my $code; |
29
|
23
|
100
|
|
|
|
50
|
if ($method =~ /^SUPER::/) { |
30
|
|
|
|
|
|
|
# Superclass WRT caller |
31
|
1
|
|
|
|
|
2
|
my $caller = caller(); |
32
|
1
|
|
|
|
|
2
|
eval { $code = $thing->Object::InsideOut::SUPER::can($caller.'::'.$method) }; |
|
1
|
|
|
|
|
7
|
|
33
|
|
|
|
|
|
|
} else { |
34
|
22
|
|
|
|
|
30
|
eval { $code = $thing->Object::InsideOut::SUPER::can($method) }; |
|
22
|
|
|
|
|
147
|
|
35
|
|
|
|
|
|
|
} |
36
|
23
|
100
|
|
|
|
49
|
if ($code) { |
37
|
9
|
|
|
|
|
23
|
return ($code); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Handle various calling methods |
41
|
14
|
|
|
|
|
11
|
my ($class, $super); |
42
|
14
|
100
|
|
|
|
45
|
if ($method !~ /::/) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Ordinary method check |
44
|
|
|
|
|
|
|
# $obj->can('x'); |
45
|
13
|
|
66
|
|
|
47
|
$class = ref($thing) || $thing; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} elsif ($method !~ /SUPER::/) { |
48
|
|
|
|
|
|
|
# Fully-qualified method check |
49
|
|
|
|
|
|
|
# $obj->can('FOO::x'); |
50
|
0
|
|
|
|
|
0
|
($class, $method) = $method =~ /^(.+)::([^:]+)$/; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} elsif ($method =~ /^SUPER::/) { |
53
|
|
|
|
|
|
|
# Superclass method check |
54
|
|
|
|
|
|
|
# $obj->can('SUPER::x'); |
55
|
1
|
|
|
|
|
2
|
$class = caller(); |
56
|
1
|
|
|
|
|
3
|
$method =~ s/SUPER:://; |
57
|
1
|
|
|
|
|
2
|
$super = 1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} else { |
60
|
|
|
|
|
|
|
# Qualified superclass method check |
61
|
|
|
|
|
|
|
# $obj->can('Foo::SUPER::x'); |
62
|
0
|
|
|
|
|
0
|
($class, $method) = $method =~ /^(.+)::SUPER::([^:]+)$/; |
63
|
0
|
|
|
|
|
0
|
$super = 1; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
14
|
|
|
|
|
22
|
my $heritage = $$GBL{'heritage'}; |
67
|
14
|
|
|
|
|
22
|
my $automethods = $$GBL{'sub'}{'auto'}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Next, check with heritage objects and Automethods |
70
|
14
|
|
|
|
|
14
|
my ($code_type, $code_dir, %code_refs); |
71
|
14
|
|
|
|
|
15
|
foreach my $pkg (@{$$GBL{'tree'}{'bu'}{$class}}) { |
|
14
|
|
|
|
|
46
|
|
72
|
|
|
|
|
|
|
# Skip self's class if SUPER |
73
|
28
|
100
|
100
|
|
|
70
|
if ($super && $class eq $pkg) { |
74
|
1
|
|
|
|
|
2
|
next; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Check heritage |
78
|
27
|
100
|
|
|
|
60
|
if (exists($$heritage{$pkg})) { |
79
|
8
|
|
|
8
|
|
35
|
no warnings; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
5830
|
|
80
|
4
|
|
|
|
|
5
|
foreach my $pkg2 (keys(%{$$heritage{$pkg}{'cl'}})) { |
|
4
|
|
|
|
|
15
|
|
81
|
4
|
50
|
|
|
|
22
|
if ($code = $pkg2->can($method)) { |
82
|
4
|
|
|
|
|
20
|
return ($code); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Check with the Automethods |
88
|
23
|
100
|
|
|
|
44
|
if (my $automethod = $$automethods{$pkg}) { |
89
|
|
|
|
|
|
|
# Call the Automethod to get a code ref |
90
|
14
|
|
|
|
|
14
|
local $CALLER::_ = $_; |
91
|
14
|
|
|
|
|
12
|
local $_ = $method; |
92
|
14
|
|
|
|
|
40
|
local $SIG{'__DIE__'} = 'OIO::trap'; |
93
|
14
|
100
|
|
|
|
32
|
if (my ($code, $ctype) = $automethod->($thing)) { |
94
|
12
|
50
|
|
|
|
117
|
if (ref($code) ne 'CODE') { |
95
|
|
|
|
|
|
|
# Not a code ref |
96
|
0
|
|
|
|
|
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
|
100
|
|
|
|
30
|
if (defined($ctype)) { |
102
|
3
|
|
|
|
|
15
|
my ($type, $dir) = $ctype =~ /(\w+)(?:[(]\s*(.*)\s*[)])?/; |
103
|
3
|
50
|
33
|
|
|
16
|
if ($type && $type =~ /CUM/i) { |
104
|
3
|
100
|
|
|
|
5
|
if ($code_type) { |
105
|
2
|
|
|
|
|
8
|
$type = ':Cumulative'; |
106
|
2
|
50
|
33
|
|
|
7
|
$dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down'; |
107
|
2
|
50
|
33
|
|
|
16
|
if ($code_type ne $type || $code_dir ne $dir) { |
108
|
|
|
|
|
|
|
# Mixed types |
109
|
0
|
|
|
|
|
0
|
my ($pkg2) = keys(%code_refs); |
110
|
0
|
|
|
|
|
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
|
|
|
|
|
2
|
$code_type = ':Cumulative'; |
116
|
1
|
50
|
33
|
|
|
4
|
$code_dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down'; |
117
|
|
|
|
|
|
|
} |
118
|
3
|
|
|
|
|
5
|
$code_refs{$pkg} = $code; |
119
|
3
|
|
|
|
|
10
|
next; |
120
|
|
|
|
|
|
|
} |
121
|
0
|
0
|
0
|
|
|
0
|
if ($type && $type =~ /CHA/i) { |
122
|
0
|
0
|
|
|
|
0
|
if ($code_type) { |
123
|
0
|
|
|
|
|
0
|
$type = ':Chained'; |
124
|
0
|
0
|
0
|
|
|
0
|
$dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down'; |
125
|
0
|
0
|
0
|
|
|
0
|
if ($code_type ne $type || $code_dir ne $dir) { |
126
|
|
|
|
|
|
|
# Mixed types |
127
|
0
|
|
|
|
|
0
|
my ($pkg2) = keys(%code_refs); |
128
|
0
|
|
|
|
|
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
|
|
|
|
|
0
|
$code_type = ':Chained'; |
134
|
0
|
0
|
0
|
|
|
0
|
$code_dir = ($dir && $dir =~ /BOT/i) ? 'bottom up' : 'top down'; |
135
|
|
|
|
|
|
|
} |
136
|
0
|
|
|
|
|
0
|
$code_refs{$pkg} = $code; |
137
|
0
|
|
|
|
|
0
|
next; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# Unknown automethod code type |
141
|
|
|
|
|
|
|
OIO::Code->die( |
142
|
0
|
|
|
|
|
0
|
'message' => "Unknown :Automethod code type: $ctype", |
143
|
|
|
|
|
|
|
'Info' => ":Automethod in package '$pkg' invoked for method '$method'"); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
9
|
50
|
|
|
|
14
|
if ($code_type) { |
147
|
|
|
|
|
|
|
# Mixed types |
148
|
0
|
|
|
|
|
0
|
my ($pkg2) = keys(%code_refs); |
149
|
0
|
|
|
|
|
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
|
|
|
|
|
38
|
return ($code); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
1
|
50
|
|
|
|
3
|
if ($code_type) { |
161
|
1
|
50
|
|
|
|
3
|
my $tree = ($code_dir eq 'bottom up') ? $$GBL{'tree'}{'bu'} : $$GBL{'tree'}{'td'}; |
162
|
1
|
50
|
|
|
|
4
|
$code = ($code_type eq ':Cumulative') |
163
|
|
|
|
|
|
|
? create_CUMULATIVE($method, $tree, \%code_refs) |
164
|
|
|
|
|
|
|
: create_CHAINED($method, $tree, \%code_refs); |
165
|
1
|
|
|
|
|
3
|
return ($code); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
0
|
return; # Can't |
169
|
|
|
|
|
|
|
}; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
*Object::InsideOut::isa = sub |
173
|
|
|
|
|
|
|
{ |
174
|
161
|
|
|
161
|
|
2564
|
my ($thing, $type) = @_; |
175
|
|
|
|
|
|
|
|
176
|
161
|
50
|
|
|
|
238
|
return ('') if (! defined($thing)); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# Metadata call for classes |
179
|
161
|
100
|
|
|
|
244
|
if (@_ == 1) { |
180
|
4
|
|
|
|
|
11
|
return Object::InsideOut::meta($thing)->get_classes(); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# Workaround for Perl bug #47233 |
184
|
157
|
50
|
|
|
|
195
|
return ('') if (! defined($type)); |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# Try original UNIVERSAL::isa() |
187
|
157
|
100
|
|
|
|
140
|
if (my $isa = eval { $thing->Object::InsideOut::SUPER::isa($type) }) { |
|
157
|
|
|
|
|
609
|
|
188
|
49
|
|
|
|
|
148
|
return ($isa); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# Next, check heritage |
192
|
108
|
|
66
|
|
|
88
|
foreach my $pkg (@{$$GBL{'tree'}{'bu'}{ref($thing) || $thing}}) { |
|
108
|
|
|
|
|
386
|
|
193
|
155
|
100
|
|
|
|
254
|
if (exists($$GBL{'heritage'}{$pkg})) { |
194
|
31
|
|
|
|
|
29
|
foreach my $pkg (keys(%{$$GBL{'heritage'}{$pkg}{'cl'}})) { |
|
31
|
|
|
|
|
73
|
|
195
|
31
|
100
|
|
|
|
160
|
if (my $isa = $pkg->isa($type)) { |
196
|
15
|
|
|
|
|
70
|
return ($isa); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
93
|
|
|
|
|
265
|
return (''); # Isn't |
203
|
|
|
|
|
|
|
}; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# Stub ourself out |
207
|
|
|
|
14
|
|
|
*Object::InsideOut::install_UNIVERSAL = sub { }; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
} # End of package's lexical scope |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
# Ensure correct versioning |
214
|
|
|
|
|
|
|
($Object::InsideOut::VERSION eq '4.03') |
215
|
|
|
|
|
|
|
or die("Version mismatch\n"); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# EOF |