| 1 | #!perl | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 10 | ▶ | use feature qw( say ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 10 | ▶ | use App::perlimports::ExportInspector (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 10 | ▶ | use Getopt::Long::Descriptive qw( describe_options ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 10 | ▶ | use List::Util qw( max ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 10 | ▶ | use Log::Dispatch (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 10 | ▶ | use Module::Runtime qw( use_module ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 10 | ▶ | use Pod::Usage qw( pod2usage ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 10 | ▶ | use Text::SimpleTable::AutoWidth (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 10 | my ( $opts, $usage ) = _options(); | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 10 | ▶ | if ( $opts->version ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | 1 | say $App::perlimports::ExportInspector::VERSION; | |||||||||||||||||||
| 19 | 1 | exit(0); | |||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 9 | ▶ | if ( $opts->help ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 1 | print $usage; | |||||||||||||||||||
| 24 | 1 | exit(0); | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 8 | ▶ | if ( $opts->verbose_help ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 1 | print STDOUT $usage; | |||||||||||||||||||
| 29 | 1 | pod2usage({ -exitval => 0 }); | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 7 | ▶ | if ( $opts->libs ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 2 | unshift @INC, ( split m{,}, $opts->libs ); | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 7 | my $logger = Log::Dispatch->new( | |||||||||||||||||||
| 37 | outputs => [ | ||||||||||||||||||||
| 38 | [ | ||||||||||||||||||||
| 39 | 'Screen', | ||||||||||||||||||||
| 40 | min_level => $opts->log_level, | ||||||||||||||||||||
| 41 | newline => 1, | ||||||||||||||||||||
| 42 | stderr => 1 | ||||||||||||||||||||
| 43 | ] | ||||||||||||||||||||
| 44 | ] | ||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 7 | ▶ | my $module = $opts->module || shift @ARGV; | ||||||||||||||||||
|
Condition66%2/3
$opts->module || shift @ARGV
MC/DC0%0/2
$opts->module || shift @ARGV
$opts->module
shift @ARGV
Truth table66%2/3
A || B
A= $opts->moduleB= shift @ARGV
| |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 7 | ▶ | if ( !$module ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 0 | say q{Mandatory parameter 'module' missing}; | |||||||||||||||||||
| 51 | 0 | print $usage; | |||||||||||||||||||
| 52 | 0 | exit(1); | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 7 | my $ei = App::perlimports::ExportInspector->new( | |||||||||||||||||||
| 56 | logger => $logger, | ||||||||||||||||||||
| 57 | module_name => $module, | ||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 7 | ▶ | if ( $ei->is_oo_class ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 0 | print 'Appears to be an Object Oriented class.' . "\n"; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 7 | ▶ | if ( @{ $ei->class_isa } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 0 | my $t = Text::SimpleTable::AutoWidth->new(); | |||||||||||||||||||
| 66 | 0 | $t->captions( ['ISA'] ); | |||||||||||||||||||
| 67 | 0 | for my $class ( @{ $ei->class_isa } ) { | |||||||||||||||||||
| 68 | 0 | $t->row($class); | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | 0 | print $t->draw; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 7 | ▶ | if ( @{ $ei->pkg_isa } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 4 | my $t = Text::SimpleTable::AutoWidth->new(); | |||||||||||||||||||
| 75 | 4 | $t->captions( ['Package ISA'] ); | |||||||||||||||||||
| 76 | 4 | for my $class ( @{ $ei->pkg_isa } ) { | |||||||||||||||||||
| 77 | 4 | $t->row($class); | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | 4 | print $t->draw; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 7 | ▶ | if ( @{ $ei->at_export_tags } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 0 | my %tags = %{ $ei->at_export_tags }; | |||||||||||||||||||
| 84 | 0 | my @keys = keys %tags; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | my @headings = ( 'Export Tag', 'Exported Symbols' ); | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | my $col1_width = max map { length($_) } @keys, $headings[0]; | |||||||||||||||||||
| 89 | 0 | my $col2_width = max map { length($_) } map ( { @{$_} } values %tags ), | |||||||||||||||||||
| 90 | $headings[1]; | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | my $t = Text::SimpleTable->new( | |||||||||||||||||||
| 93 | [ $col1_width, 'Export Tag' ], | ||||||||||||||||||||
| 94 | [ $col2_width, 'Exported Symbols' ] | ||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | my $i = 0; | |||||||||||||||||||
| 98 | 0 | for my $key ( sort @keys ) { | |||||||||||||||||||
| 99 | 0 | $t->row( $key, join "\n", sort @{ $tags{$key} } ); | |||||||||||||||||||
| 100 | 0 | ++$i; | |||||||||||||||||||
| 101 | 0 | ▶ | $t->hr if $i < scalar @keys; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | 0 | print $t->draw; | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 7 | ▶ | if ( @{ $ei->at_export_fail } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | 0 | my $t = Text::SimpleTable::AutoWidth->new(); | |||||||||||||||||||
| 108 | 0 | $t->captions( ['@EXPORT_FAIL'] ); | |||||||||||||||||||
| 109 | 0 | for my $val ( sort @{ $ei->at_export_fail } ) { | |||||||||||||||||||
| 110 | 0 | $t->row($val); | |||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | 0 | print $t->draw; | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 7 | ▶ | if ( $ei->has_implicit_exports ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | 6 | my $t = Text::SimpleTable::AutoWidth->new(); | |||||||||||||||||||
| 117 | 6 | ▶ | if ( $ei->implicit_export_names_match_values ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 118 | 6 | $t->captions( ['Default Exported Symbols'] ); | |||||||||||||||||||
| 119 | 6 | for my $symbol ( sort $ei->implicit_export_names ) { | |||||||||||||||||||
| 120 | 40 | $t->row($symbol); | |||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | else { | ||||||||||||||||||||
| 124 | 0 | $t->captions( [ 'Default Export Symbol', 'Import Name' ] ); | |||||||||||||||||||
| 125 | 0 | for my $key ( sort $ei->implicit_export_names ) { | |||||||||||||||||||
| 126 | 0 | $t->row( $key, $ei->implicit_exports->{$key} ); | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | } | ||||||||||||||||||||
| 129 | 6 | print $t->draw; | |||||||||||||||||||
| 130 | 6 | printf( "%i symbols\n", scalar $ei->implicit_export_names ); | |||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 7 | my $exports = $ei->explicit_exports; | |||||||||||||||||||
| 134 | 7 | ▶ | if ( !keys %{$exports} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 135 | 0 | print 'No exported symbols found' . "\n"; | |||||||||||||||||||
| 136 | 0 | exit(0); | |||||||||||||||||||
| 137 | } | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | { | ||||||||||||||||||||
| 140 | 7 | my $t = Text::SimpleTable::AutoWidth->new(); | |||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 7 | ▶ | if ( $ei->explicit_export_names_match_values ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 143 | 6 | $t->captions( ['All Exportable Symbols'] ); | |||||||||||||||||||
| 144 | 6 | for my $symbol ( sort $ei->explicit_export_names ) { | |||||||||||||||||||
| 145 | 40 | $t->row($symbol); | |||||||||||||||||||
| 146 | } | ||||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | else { | ||||||||||||||||||||
| 149 | 1 | $t->captions( [ 'Explicit Export Symbol', 'Import Name' ] ); | |||||||||||||||||||
| 150 | 1 | for my $key ( sort $ei->explicit_export_names ) { | |||||||||||||||||||
| 151 | 1 | $t->row( $key, $exports->{$key} ); | |||||||||||||||||||
| 152 | } | ||||||||||||||||||||
| 153 | } | ||||||||||||||||||||
| 154 | 7 | print $t->draw; | |||||||||||||||||||
| 155 | 7 | printf( "%i symbols\n", scalar $ei->explicit_export_names ); | |||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 7 | require Data::Dumper; ## no perlimports | |||||||||||||||||||
| 158 | 7 | $logger->debug( Data::Dumper::Dumper($ei) ); | |||||||||||||||||||
| 159 | } | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | 10 | ▶ | sub _options { | ||||||||||||||||||
|
Subroutine
_options: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 162 | 10 | return describe_options( | |||||||||||||||||||
| 163 | 'dump-perl-exports %o', | ||||||||||||||||||||
| 164 | [ | ||||||||||||||||||||
| 165 | 'module|m=s', 'The module to inspect for exports', | ||||||||||||||||||||
| 166 | ], | ||||||||||||||||||||
| 167 | [], | ||||||||||||||||||||
| 168 | [ | ||||||||||||||||||||
| 169 | 'libs=s', | ||||||||||||||||||||
| 170 | 'Comma-separated list of library paths to include (eg --libs lib,t/lib,dev/lib)', | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | ], | ||||||||||||||||||||
| 173 | [], | ||||||||||||||||||||
| 174 | [ 'version', 'Print installed version', { shortcircuit => 1 } ], | ||||||||||||||||||||
| 175 | [ | ||||||||||||||||||||
| 176 | 'log-level|l=s', 'Print messages to STDERR', | ||||||||||||||||||||
| 177 | { default => 'warning' } | ||||||||||||||||||||
| 178 | ], | ||||||||||||||||||||
| 179 | [ 'help', 'Print usage message and exit', { shortcircuit => 1 } ], | ||||||||||||||||||||
| 180 | [ | ||||||||||||||||||||
| 181 | 'verbose-help', 'Print usage message and documentation ', | ||||||||||||||||||||
| 182 | { shortcircuit => 1 } | ||||||||||||||||||||
| 183 | ], | ||||||||||||||||||||
| 184 | ); | ||||||||||||||||||||
| 185 | } | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | # PODNAME: dump-perl-exports | ||||||||||||||||||||
| 188 | # ABSTRACT: A command line utility for describing what a class exports | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | __END__ | ||||||||||||||||||||