Util/FindMethods.pm

filter: Statementstmt 97.6% 41 / 42 Branchbran 65.0% 13 / 20 Conditioncond 63.6% 7 / 11 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 80.0% 68 / 85 CC 18 SCAR 28.4
CC
18
Cov
84%
FindMethods
20.7
BEGIN
1.0
BEGIN
1.0
CRAP 17.1
« blib/lib/MOP4Import/Base/CLI_JSON.pm ↑ Summary blib/lib/MOP4Import/NamedCodeAttributes.pm »
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 ||= {}
l!l
287
MC/DC100%1/1
$visited ||= {}
$visited
Truth table100%2/2
A
A= $visited
Aresult
11
00
16 35 ▶ $found ||= {};
Condition100%2/2
$found ||= {}
l!l
287
MC/DC100%1/1
$found ||= {}
$found
Truth table100%2/2
A
A= $found
Aresult
11
00
17 35 ▶ my $class = ref($obj) ? ref($obj) : $obj;
Branch: 1 branch
BranchTrueFalseTotal
ref $obj ? : 0 35 35
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
BranchTrueFalseTotal
if ($pattern) 1849 0 1849
24 1849 ▶ if (ref $pattern eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pattern eq 'CODE') { } 1849 0 1849
25 1849 ▶ $pattern->($_) or next;
Branch: 1 branch
BranchTrueFalseTotal
&$pattern($_) or next 1828 21 1849
26 } else {
27 0 ▶ $_ =~ $pattern or next;
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /$pattern/ or next 0 0 0
28 }
29 }
30 21 my $globOrCode = $symtab->{$orig};
31 21 ▶ if (ref $globOrCode eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $globOrCode eq 'CODE') { } 0 21 21
elsif (ref \$globOrCode eq 'GLOB' and *{$globOrCode;}{'CODE'}) { } 11 10 21
32 ; #ok
33 21 ▶ } elsif (ref \$globOrCode eq 'GLOB' and *{$globOrCode}{CODE}) {
Condition50%1/2
ref \$globOrCode eq "GLOB" and *{$globOrCode;}{"CODE"}
!ll
021
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"
Aresult
00
11
34 ; #ok
35 } else {
36 10 next;
37 }
38 11 ▶ $found->{$_} //= $class;
Condition33%1/3
$found->{$_} //= $class
l!l&&r!l&&!r
0110
MC/DC0%0/2
$found->{$_} //= $class
$found->{$_} $class
Truth table33%1/3
A //= B
A= $found->{$_}B= $class
ABresult
1X1
011
000
39 }
40  
41 35 my $isa = $symtab->{ISA};
42 35 ▶ if (defined $isa and *{$isa}{ARRAY}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $isa and *{$isa;}{"ARRAY"}) 35 0 35
Condition50%1/2
defined $isa and *{$isa;}{"ARRAY"}
!ll
035
MC/DC0%0/1
defined $isa and *{$isa;}{"ARRAY"}
defined $isa
Truth table50%1/2
A
A= defined $isa
Aresult
00
11
43 35 foreach my $super (@{*{$isa}{ARRAY}}) {
44 FindMethods($super, $pattern, $visited, $found)
45 32 ▶ unless $visited->{$super};
Branch: 1 branch
BranchTrueFalseTotal
unless $visited->{$super} 28 4 32
46 }
47 }
48  
49 35 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 7 28 35
50 7 sort keys %$found
51 } else {
52 28 $found;
53 }
54 }
55  
56 7 1;
« blib/lib/MOP4Import/Base/CLI_JSON.pm ↑ Summary blib/lib/MOP4Import/NamedCodeAttributes.pm »