| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | while (my $line = <$ifh>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 829 | ▶ | $in_function = 1 if ($line =~ m/^sub\s+$function\W/msx); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 829 | ▶ | next if !$in_function; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 43 | $found = 1; | |||||||||||||||||||||||||||
| 47 | 43 | print $line; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 43 | ▶ | $in_function = 0 if $line =~ m/^}\s*$/msx; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 1 | close $ifh; | |||||||||||||||||||||||||||
| 52 | 1 | ▶ | print STDERR "cannot find '$module::$function'\n" if !$found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | $errors++ if $? || !$found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$? or not $found
MC/DC0%0/2
$? or not $found
$?
not $found
Truth table33%1/3
A or not(B)
A= $?B= not $found
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | exit ($errors != 0); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||||||||||