line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package YATT::Lite::Util::FindMethods; |
2
|
2
|
|
|
2
|
|
4017
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
66
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings qw(FATAL all NONFATAL misc); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
78
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
10
|
use Exporter qw(import); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
96
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw(FindMethods); |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
11
|
use YATT::Lite::Util qw(symtab); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
603
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub FindMethods { |
11
|
|
|
|
|
|
|
# depth first, pre-order search of 'sub'. |
12
|
|
|
|
|
|
|
# In the real sense, this should be called 'Findsubs'. |
13
|
3
|
|
|
3
|
0
|
607
|
my ($obj, $pattern, $visited, $found) = @_; |
14
|
3
|
|
100
|
|
|
12
|
$visited ||= {}; |
15
|
3
|
|
100
|
|
|
9
|
$found ||= {}; |
16
|
3
|
100
|
|
|
|
7
|
my $class = ref($obj) ? ref($obj) : $obj; |
17
|
3
|
|
|
|
|
5
|
$visited->{$class} = 1; |
18
|
3
|
|
|
|
|
10
|
my $symtab = symtab($class); |
19
|
3
|
|
|
|
|
11
|
local $_; |
20
|
3
|
|
|
|
|
16
|
foreach my $orig (keys %$symtab) { |
21
|
67
|
|
|
|
|
284
|
$_ = $orig; |
22
|
67
|
50
|
|
|
|
142
|
if ($pattern) { |
23
|
67
|
50
|
|
|
|
122
|
if (ref $pattern eq 'CODE') { |
24
|
67
|
100
|
|
|
|
113
|
$pattern->($_) or next; |
25
|
|
|
|
|
|
|
} else { |
26
|
0
|
0
|
|
|
|
0
|
$_ =~ $pattern or next; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
4
|
|
|
|
|
28
|
my $glob = $symtab->{$orig}; |
30
|
4
|
100
|
|
|
|
7
|
next unless *{$glob}{CODE}; |
|
4
|
|
|
|
|
25
|
|
31
|
2
|
|
33
|
|
|
16
|
$found->{$_} //= $class; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
17
|
my $isa = $symtab->{ISA}; |
35
|
3
|
50
|
50
|
|
|
11
|
if (defined $isa and *{$isa}{ARRAY}) { |
|
3
|
|
|
|
|
14
|
|
36
|
3
|
|
|
|
|
4
|
foreach my $super (@{*{$isa}{ARRAY}}) { |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
9
|
|
37
|
|
|
|
|
|
|
FindMethods($super, $pattern, $visited, $found) |
38
|
2
|
50
|
|
|
|
11
|
unless $visited->{$super}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
3
|
100
|
|
|
|
14
|
if (wantarray) { |
43
|
1
|
|
|
|
|
10
|
sort keys %$found |
44
|
|
|
|
|
|
|
} else { |
45
|
2
|
|
|
|
|
6
|
$found; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |