| 1 | package YATT::Lite::Util::FindMethods; | ||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 3 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 3 | ▶ | use Exporter qw(import); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 3 | our @EXPORT = qw(FindMethods); | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 3 | ▶ | use YATT::Lite::Util qw(symtab); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | ▶ | sub FindMethods { | ||||||||||||||||||
|
Subroutine
FindMethods: called CC=17 SCAR=29.5
Pod
undocumented
| |||||||||||||||||||||
| 11 | # depth first, pre-order search of 'sub'. | ||||||||||||||||||||
| 12 | # In the real sense, this should be called 'Findsubs'. | ||||||||||||||||||||
| 13 | 3 | my ($obj, $pattern, $visited, $found) = @_; | |||||||||||||||||||
| 14 | 3 | ▶ | $visited ||= {}; | ||||||||||||||||||
|
Condition100%2/2
$visited ||= {}
MC/DC100%1/1
$visited ||= {}
$visited
Truth table100%2/2
A
A= $visited
| |||||||||||||||||||||
| 15 | 3 | ▶ | $found ||= {}; | ||||||||||||||||||
|
Condition100%2/2
$found ||= {}
MC/DC100%1/1
$found ||= {}
$found
Truth table100%2/2
A
A= $found
| |||||||||||||||||||||
| 16 | 3 | ▶ | my $class = ref($obj) ? ref($obj) : $obj; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | 3 | $visited->{$class} = 1; | |||||||||||||||||||
| 18 | 3 | my $symtab = symtab($class); | |||||||||||||||||||
| 19 | 3 | local $_; | |||||||||||||||||||
| 20 | 3 | foreach my $orig (keys %$symtab) { | |||||||||||||||||||
| 21 | 66 | $_ = $orig; | |||||||||||||||||||
| 22 | 66 | ▶ | if ($pattern) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 66 | ▶ | if (ref $pattern eq 'CODE') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 66 | ▶ | $pattern->($_) or next; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | } else { | ||||||||||||||||||||
| 26 | 0 | ▶ | $_ =~ $pattern or next; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | 4 | my $glob = $symtab->{$orig}; | |||||||||||||||||||
| 30 | 4 | ▶ | next if ref $glob; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | # { | ||||||||||||||||||||
| 32 | # local $@; | ||||||||||||||||||||
| 33 | # # To avoid 'Not a GLOB reference'. | ||||||||||||||||||||
| 34 | # my $is_code = eval {*{$glob}{CODE}}; | ||||||||||||||||||||
| 35 | # if ($@) { | ||||||||||||||||||||
| 36 | # next; | ||||||||||||||||||||
| 37 | # } elsif (not $is_code) { | ||||||||||||||||||||
| 38 | # next; | ||||||||||||||||||||
| 39 | # } | ||||||||||||||||||||
| 40 | # } | ||||||||||||||||||||
| 41 | 4 | ▶ | next unless *{$glob}{CODE}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 2 | ▶ | $found->{$_} //= $class; | ||||||||||||||||||
|
Condition33%1/3
$found->{$_} //= $class
MC/DC0%0/2
$found->{$_} //= $class
$found->{$_}
$class
Truth table33%1/3
A //= B
A= $found->{$_}B= $class
| |||||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 3 | my $isa = $symtab->{ISA}; | |||||||||||||||||||
| 46 | 3 | ▶ | if (defined $isa and *{$isa}{ARRAY}) { | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
defined $isa and *{$isa;}{"ARRAY"}
MC/DC0%0/1
defined $isa and *{$isa;}{"ARRAY"}
defined $isa
Truth table50%1/2
A
A= defined $isa
| |||||||||||||||||||||
| 47 | 3 | foreach my $super (@{*{$isa}{ARRAY}}) { | |||||||||||||||||||
| 48 | FindMethods($super, $pattern, $visited, $found) | ||||||||||||||||||||
| 49 | 2 | ▶ | unless $visited->{$super}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 3 | ▶ | if (wantarray) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 1 | sort keys %$found | |||||||||||||||||||
| 55 | } else { | ||||||||||||||||||||
| 56 | 2 | $found; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 3 | 1; | |||||||||||||||||||