lib/App/FindCallers.pm

filter: Statementstmt 68.1% 30 / 44 Branchbran 57.1% 8 / 14 Conditioncond 57.1% 4 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 3 totaltotal 62.2% 51 / 82 CC 12 SCAR 16.7
CC
12
Cov
65%
find_in_file
8.3
report
6.0
main
6.0
CRAP 5.3
↑ Summary script/find_callers.pl »
1 package App::FindCallers;
2 # ABSTRACT: Find the callers of a given function in a directory tree
3  
4 1 our $VERSION = '0.04';
5  
6 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub report {
Subroutine report: not called CC=2 SCAR=17.9
Pod undocumented
14 0 my ($filename, $f, $nestlevel) = @_;
15 0 my $indent = " " x $nestlevel;
16 0 my $message = "Called from";
17 0 ▶ if ($nestlevel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nestlevel) 0 0 0
18 0 $message = "Defined in"
19 }
20 0 my $location = $filename . ":" . $f->line_number;
21  
22 0 printf "%s%s %s() in %s\n", $indent, $message, $f->name, $location;
23 }
24  
25 1 ▶sub find_in_file {
Subroutine find_in_file: called CC=8 SCAR=21.1
Pod undocumented
26 1 my ($function, $filename, $cb) = @_;
27 1 ▶ $cb ||= \&report;
Condition50%1/2
$cb ||= \&App::FindCallers::report
l!l
10
MC/DC0%0/1
$cb ||= \&App::FindCallers::report
$cb
Truth table50%1/2
A
A= $cb
Aresult
11
00
28 1 my $document = PPI::Document->new($filename);
29 1 ▶ unless ($document) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($document) 0 1 1
30 0 say "Failed to parse $filename " . PPI::Document->errstr;
31 0 return;
32 }
33 1 $document->index_locations;
34 68 ▶ my $references = $document->find(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
35 68 ▶ $_[1]->isa('PPI::Token::Word') and $_[1]->content eq $function
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Word") and $_[1]->content eq $function 12 56 68
36 1 });
37 1 ▶ return unless $references;
Branch: 1 branch
BranchTrueFalseTotal
unless $references 0 1 1
38 1 for my $f (@$references) {
39 3 my $nestlevel = 0;
40 3 ▶ while ($f = $f->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f = $f->parent) 14 3 17
41 # XXX this makes skip the declaration of said sub,
42 # but also makes it not detect recursive calls
43 14 ▶ if ($f->isa('PPI::Statement::Sub') and $f->name ne $function) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->isa("PPI::Statement::Sub") and $f->name ne $function) 4 10 14
Condition100%3/3
$f->isa("PPI::Statement::Sub") and $f->name ne $function
!ll&&!rl&&r
914
MC/DC100%2/2
$f->isa("PPI::Statement::Sub") and $f->name ne $function
$f->isa("PPI::Statement::Sub") $f->name ne $function
Truth table100%3/3
A and B
A= $f->isa("PPI::Statement::Sub")B= $f->name ne $function
ABresult
0X0
100
111
44 4 $cb->($filename, $f, $nestlevel);
45 4 $nestlevel++;
46 }
47 };
48 }
49 }
50  
51 0 ▶sub main {
Subroutine main: not called CC=2 SCAR=17.9
Pod undocumented
52 0 my ($funcname, $directory, $cb) = @_;
53 0 ▶ $directory ||= '.';
Condition0%0/2
$directory ||= "."
l!l
00
MC/DC0%0/1
$directory ||= "."
$directory
Truth table0%0/2
A
A= $directory
Aresult
11
00
54 0 ▶ find({ wanted => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
55 0 ▶ if (/\.p[lm]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\.p[lm]$/) 0 0 0
56 0 find_in_file $funcname, $_;
57 }
58 0 }, follow => 1, no_chdir => 1 }, $directory);
59 }
60  
61 1 1;
62  
63 __END__
↑ Summary script/find_callers.pl »