bin/pmeth

filter: Statementstmt 88.8% 48 / 54 Branchbran 62.5% 10 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 84.8% 67 / 79 CC 11 SCAR 17.3
CC
11
Cov
83%
show_methods
10.3
BEGIN
2.1
declared
2.0
CRAP 5.6
« bin/pminst ↑ Summary bin/pmexp »
1 #!/usr/bin/env perl
2 # pmeth -- show a class's methods
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.0';
9  
10 # ------ define variables
11 1 my $ancestor = undef; # ancestor
12 1 my $errors = 0; # error count
13 1 my %got_def = (); # got definition already
14 1 my $name = undef; # symbol name
15  
16 1 ▶BEGIN { $^W = 1 }
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶BEGIN { die "usage: $0 module\n" unless @ARGV == 1 }
Subroutine BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV == 1 0 1 1
18  
19 1 $errors = 0;
20  
21 1 %got_def = ();
22  
23 1 show_methods($ARGV[0]);
24 1 show_methods("UNIVERSAL", $ARGV[0]);
25  
26 2 ▶sub show_methods {
Subroutine show_methods: called CC=9 SCAR=23.3
27 2 my $module = shift;
28 2 my @indirect = @_;
29 2 my @baseclasses = @indirect[ 0 .. ($#indirect-1) ];
30 2 eval "local \$^W = 0; require $module";
31 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
32 0 $@ =~ s/at \(eval.*$//;
33 0 warn "$0: $@";
34 0 $errors++;
35 0 return;
36 }
37 1 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 foreach $name ( sort keys %{ $module . "::" } ) {
39 1 ▶use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 16 ▶ print '[constant] ' if declared($module . "::" . $name);
Branch: 1 branch
BranchTrueFalseTotal
if &declared($module . '::' . $name) 0 16 16
41  
42 16 ▶ if (defined &{ $module . "::" . $name } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &{$module . '::' . $name;}) 13 3 16
43 13 ▶ print "[overridden] " if $got_def{$name}++;
Branch: 1 branch
BranchTrueFalseTotal
if $got_def{$name}++ 0 13 13
44 13 ▶ if (@indirect) {
Branch: 1 branch
BranchTrueFalseTotal
if (@indirect) { } 6 7 13
45 6 print join(" via ", $name, $module, @baseclasses), "\n";
46 } else {
47 7 print "$name\n";
48 }
49 }
50 }
51 2 ▶ if (my @parents = @{ $module . "::ISA" } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@parents) = @{$module . '::ISA';}) 0 2 2
52 0 foreach $ancestor (@parents) {
53 0 show_methods($ancestor, $module, @indirect);
54 }
55 }
56 }
57  
58 16 ▶sub declared ($) {
Subroutine declared: called CC=2 SCAR=7.0
59 1 ▶ use constant 1.01; # don't omit this!
Subroutine BEGIN: called CC=1 SCAR=0.0
60 16 my $name = shift;
61 16 $name =~ s/^::/main::/;
62 16 my $pkg = caller;
63 16 ▶ my $full_name = $name =~ /::/ ? $name : "${pkg}::$name";
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /::/ ? : 16 0 16
64 16 $constant::declared{$full_name};
65 }
66  
67 1 exit ($errors != 0);
68  
69 __END__
« bin/pminst ↑ Summary bin/pmexp »