File Coverage

lib/App/Isa/Splain.pm
Criterion Covered Total %
statement 40 60 66.6
branch 8 18 44.4
condition 1 6 16.6
subroutine 10 16 62.5
pod 3 3 100.0
total 62 103 60.1


line stmt bran cond sub pod time code
1 3     3   25850 use 5.006; # our
  3         7  
2 3     3   21 use strict;
  3         3  
  3         54  
3 3     3   14 use warnings;
  3         3  
  3         188  
4              
5             package App::Isa::Splain;
6              
7             our $VERSION = '0.002900'; # TRIAL
8              
9             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
10              
11             # ABSTRACT: Visualize Module Hierarchies on the command line
12              
13 3     3   1191 use Module::Load qw( load );
  3         2314  
  3         12  
14 3     3   134 use Carp qw( croak );
  3         3  
  3         162  
15 3     3   1109 use Devel::Isa::Explainer qw( explain_isa );
  3         5  
  3         227  
16              
17             # Perl critic is broken. This is not a void context.
18             ## no critic (BuiltinFunctions::ProhibitVoidMap)
19 3     3   12 use constant 1.03 ( { map { ( ( sprintf '_E%x', $_ ), ( sprintf ' E<%s#%d>', __PACKAGE__, $_ ) ) } 1 .. 3 } );
  3         36  
  3         6  
  9         193  
20              
21 3     3   12 use namespace::clean;
  3         4  
  3         9  
22              
23              
24              
25              
26              
27              
28              
29              
30              
31              
32              
33             sub new {
34 2     2 1 5 my ( $class, @args ) = @_;
35 2 50       12 my (%args) = ref $args[0] ? %{ $args[0] } : @args;
  0         0  
36 2         10 return bless \%args, $class;
37             }
38              
39              
40              
41              
42              
43              
44              
45              
46              
47              
48              
49              
50             sub new_from_ARGV {
51 2 50   2 1 33 my (@args) = defined $_[1] ? @{ $_[1] } : @ARGV;
  2         7  
52 2         3 my $module;
53             my @load_modules;
54 2         8 while ( @args ) {
55 3         4 my $argument = shift @args;
56 3 100 33     24 if ( not defined $module and $argument !~ /\A-/sx ) {
57 2         4 $module = $argument;
58 2         5 next;
59             }
60 1 50       6 if( $argument =~ /\A-M(.*)\z/sx ) {
61 1         4 push @load_modules, $1;
62 1         2 next;
63             }
64             ## no critic (RequireCheckedSyscalls)
65 0 0       0 if( '--help' eq $argument) {
66 0         0 print _help();
67 0         0 exit;
68             }
69 0 0       0 if( '--version' eq $argument ) {
70 0         0 print _version();
71 0         0 exit;
72             }
73 0         0 croak 'Unexpected argument ' . $argument . _E3 . qq[\nSee $0 --help for more information];
74             }
75 2 50       7 defined $module or croak 'Expected a module name, got none' . _E1 . qq[\nSee $0 --help for more information];
76 2 100       12 return $_[0]->new( module => $module, load_modules => [ @load_modules ? @load_modules : $module ] );
77             }
78              
79 0     0     sub _load_modules { return @{ $_[0]->{load_modules} } }
  0            
80 0     0     sub _module { return $_[0]->{module} }
81 0   0 0     sub _output { return ( $_[0]->{output} || *STDOUT ) }
82              
83              
84              
85              
86              
87              
88              
89             sub run {
90 0     0 1   my ($self) = @_;
91 0           load $_ for $self->_load_modules;
92             croak "Could not print to output handle: $! $^E" . _E2
93 0 0         unless print { $self->_output } explain_isa( $self->_module );
  0            
94              
95 0           return 0;
96             }
97              
98             sub _help {
99 0     0     return <<"EOF";
100             Usage: $0 [OPTIONS] MODNAME
101             Load and inspect MODNAME's ISA Inheritance.
102              
103             OPTIONS:
104             -MLoad::Module - Load "Load::Module" instead of MODNAME ( May be
105             specified multiple times )
106              
107             --help - Show this help and exit
108             --version - Show version and exit
109             EOF
110             }
111              
112             sub _version {
113 0     0     my $pkg = __PACKAGE__;
114 0           return <<"EOF";
115             $0 ($pkg) $VERSION
116             EOF
117             }
118              
119             1;
120              
121             __END__