| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 38 | 1 | print "$module optionally exports ", | |||||||||||||||||
| 39 | commify_series(@list), "\n"; | ||||||||||||||||||
| 40 | } | ||||||||||||||||||
| 41 | 1 | ▶ | if (%table = %{ $module . "::EXPORT_TAGS" } ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 53 | (@_ == 1) ? $_[0] : | ||||||||||||||||||
| 54 | (@_ == 2) ? join(" and ", @_) : | ||||||||||||||||||
| 55 | join(", ", @_[0 .. ($#_-1)], "and $_[-1]"); | ||||||||||||||||||
| 56 | } | ||||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||