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