bin/pmfunc

filter: Statementstmt 90.4% 38 / 42 Branchbran 70.0% 14 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 80.5% 58 / 72 CC 2 SCAR 3.2
CC
2
Cov
82%
BEGIN
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« blib/lib/pmtools.pm ↑ Summary bin/pmcat »
1 #!/usr/bin/env perl
2 # pmfunc -- show a function
3  
4 # ------ pragmas
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '2.0';
9  
10 # ------ define variables
11 1 my $errors = 0; # error count
12 1 my $file = undef; # module file path
13 1 my $function = undef; # function name
14 1 my $module = undef; # module name
15 1 my $ok = undef; # OK count
16  
17 1 ▶BEGIN { $^W = 1 }
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶BEGIN { die "usage: $0 module ...\n" unless @ARGV }
Subroutine BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 1 1
19  
20 1 ▶use FindBin qw($Bin);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 $errors = 0;
23  
24 1 for my $arg (@ARGV) {
25 1 ($module, $function) = $arg =~ /(\w.*)::(\w+)$/;
26 1 ▶ if (!defined($module)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $module) 0 1 1
27 0 print STDERR "Sorry, '$arg' is not the name of a function in a module.\n";
28 0 next;
29 }
30  
31 1 $file = `$^X -S $Bin/pmpath $module`;
32 1 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 1 1
33 0 $errors++;
34 0 next;
35 }
36 1 chomp $file;
37  
38 1 my $found = 0;
39 1 my $ifh;
40 1 my $in_function = 0;
41 1 ▶ open $ifh, '<', $file or die "cannot open '$file': $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $ifh, "<", $file or die "cannot open '${file}': $!\n" 1 0 1
42 1 ▶ while (my $line = <$ifh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $ifh)) 829 1 830
43 829 ▶ $in_function = 1 if ($line =~ m/^sub\s+$function\W/msx);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^sub\s+$function\W/msx 1 828 829
44 829 ▶ next if !$in_function;
Branch: 1 branch
BranchTrueFalseTotal
unless $in_function 786 43 829
45  
46 43 $found = 1;
47 43 print $line;
48  
49 43 ▶ $in_function = 0 if $line =~ m/^}\s*$/msx;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^}\s*$/msx 1 42 43
50 }
51 1 close $ifh;
52 1 ▶ print STDERR "cannot find '$module::$function'\n" if !$found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 0 1 1
53  
54 1 ▶ $errors++ if $? || !$found;
Branch: 1 branch
BranchTrueFalseTotal
if $? or not $found 0 1 1
Condition33%1/3
$? or not $found
l!l&&r!l&&!r
001
MC/DC0%0/2
$? or not $found
$? not $found
Truth table33%1/3
A or not(B)
A= $?B= not $found
ABresult
1X1
011
000
55 }
56  
57 1 exit ($errors != 0);
58  
59 __END__
« blib/lib/pmtools.pm ↑ Summary bin/pmcat »