bin/pmexp

filter: Statementstmt 82.9% 34 / 41 Branchbran 50.0% 8 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 76.5% 49 / 64 CC 5 SCAR 10.1
CC
5
Cov
74%
commify_series
5.3
BEGIN
2.1
BEGIN
1.0
CRAP 2.8
« bin/pmeth ↑ Summary bin/pmdesc »
1 #!/usr/bin/env perl
2 # pmexp -- show a module's exports
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 $errors = 0; # error count
12 1 my @list = (); # list of module exports
13 1 my $module = undef; # module name
14 1 my %table = (); # module export tags
15 1 my $tag = undef; # module export tag
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 $errors = 0;
21  
22 1 for $module (@ARGV) {
23 1 eval "local \$^W = 0; require $module";
24 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
25 0 $@ =~ s/at \(eval.*$//;
26 0 warn "$0: $@";
27 0 $errors++;
28 0 next;
29 }
30  
31 1 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶ if (@list = @{ $module . "::EXPORT" } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@list = @{$module . '::EXPORT';}) 1 0 1
33 1 ▶use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 print "$module automatically exports ",
35 commify_series(@list), "\n";
36 }
37 1 ▶ if (@list = @{ $module . "::EXPORT_OK" } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@list = @{$module . '::EXPORT_OK';}) 1 0 1
38 1 print "$module optionally exports ",
39 commify_series(@list), "\n";
40 }
41 1 ▶ if (%table = %{ $module . "::EXPORT_TAGS" } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%table = %{$module . '::EXPORT_TAGS';}) 0 1 1
42 0 for $tag (sort keys %table) {
43 0 print "$module export tag '$tag' includes ", commify_series(@{$table{$tag}}), "\n";
44 }
45 }
46 }
47  
48 1 exit($errors != 0);
49  
50  
51 2 ▶sub commify_series {
Subroutine commify_series: called CC=4 SCAR=16.6
52 2 ▶ (@_ == 0) ? '' :
Branch: 3 branches
BranchTrueFalseTotal
@_ == 0 ? : 0 2 2
@_ == 1 ? : 0 2 2
@_ == 2 ? : 0 2 2
53 (@_ == 1) ? $_[0] :
54 (@_ == 2) ? join(" and ", @_) :
55 join(", ", @_[0 .. ($#_-1)], "and $_[-1]");
56 }
57  
58 __END__
« bin/pmeth ↑ Summary bin/pmdesc »