blib/lib/YATT/Lite/Util/FindMethods.pm

filter: Statementstmt 97.6% 41 / 42 Branchbran 65.0% 13 / 20 Conditioncond 66.6% 6 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 81.7% 67 / 82 CC 17 SCAR 27.5
CC
17
Cov
85%
FindMethods
19.1
BEGIN
1.0
BEGIN
1.0
CRAP 15.6
« blib/lib/YATT/Lite/Util.pm ↑ Summary blib/lib/YATT/Lite/LRXML/AltTree.pm »
1 package YATT::Lite::Util::FindMethods;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 our @EXPORT = qw(FindMethods);
7  
8 2 ▶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 ||= {}
l!l
21
MC/DC100%1/1
$visited ||= {}
$visited
Truth table100%2/2
A
A= $visited
Aresult
11
00
15 3 ▶ $found ||= {};
Condition100%2/2
$found ||= {}
l!l
21
MC/DC100%1/1
$found ||= {}
$found
Truth table100%2/2
A
A= $found
Aresult
11
00
16 3 ▶ my $class = ref($obj) ? ref($obj) : $obj;
Branch: 1 branch
BranchTrueFalseTotal
ref $obj ? : 1 2 3
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
BranchTrueFalseTotal
if ($pattern) 66 0 66
23 66 ▶ if (ref $pattern eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pattern eq 'CODE') { } 66 0 66
24 66 ▶ $pattern->($_) or next;
Branch: 1 branch
BranchTrueFalseTotal
&$pattern($_) or next 4 62 66
25 } else {
26 0 ▶ $_ =~ $pattern or next;
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /$pattern/ or next 0 0 0
27 }
28 }
29 4 my $glob = $symtab->{$orig};
30 4 ▶ next if ref $glob;
Branch: 1 branch
BranchTrueFalseTotal
if ref $glob 0 4 4
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
BranchTrueFalseTotal
unless *{$glob;}{"CODE"} 2 2 4
42 2 ▶ $found->{$_} //= $class;
Condition33%1/3
$found->{$_} //= $class
l!l&&r!l&&!r
020
MC/DC0%0/2
$found->{$_} //= $class
$found->{$_} $class
Truth table33%1/3
A //= B
A= $found->{$_}B= $class
ABresult
1X1
011
000
43 }
44  
45 3 my $isa = $symtab->{ISA};
46 3 ▶ if (defined $isa and *{$isa}{ARRAY}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $isa and *{$isa;}{"ARRAY"}) 3 0 3
Condition50%1/2
defined $isa and *{$isa;}{"ARRAY"}
!ll
03
MC/DC0%0/1
defined $isa and *{$isa;}{"ARRAY"}
defined $isa
Truth table50%1/2
A
A= defined $isa
Aresult
00
11
47 3 foreach my $super (@{*{$isa}{ARRAY}}) {
48 FindMethods($super, $pattern, $visited, $found)
49 2 ▶ unless $visited->{$super};
Branch: 1 branch
BranchTrueFalseTotal
unless $visited->{$super} 2 0 2
50 }
51 }
52  
53 3 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1 2 3
54 1 sort keys %$found
55 } else {
56 2 $found;
57 }
58 }
59  
60 2 1;
« blib/lib/YATT/Lite/Util.pm ↑ Summary blib/lib/YATT/Lite/LRXML/AltTree.pm »