File Coverage

lib/App/Isa/Splain.pm
Criterion Covered Total %
statement 40 51 78.4
branch 8 14 57.1
condition 1 6 16.6
subroutine 10 14 71.4
pod 3 3 100.0
total 62 88 70.4


line stmt bran cond sub pod time code
1 3     3   26792 use 5.006; # our
  3         6  
2 3     3   10 use strict;
  3         3  
  3         49  
3 3     3   16 use warnings;
  3         2  
  3         192  
4              
5             package App::Isa::Splain;
6              
7             our $VERSION = '0.002000';
8              
9             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
10              
11             # ABSTRACT: Visualize Module Hierarchies on the command line
12              
13 3     3   1205 use Module::Load qw( load );
  3         2307  
  3         13  
14 3     3   129 use Carp qw( croak );
  3         4  
  3         154  
15 3     3   1004 use Devel::Isa::Explainer qw( explain_isa );
  3         5  
  3         216  
16              
17             # Perl critic is broken. This is not a void context.
18             ## no critic (BuiltinFunctions::ProhibitVoidMap)
19 3     3   15 use constant 1.03 ( { map { ( ( sprintf '_E%x', $_ ), ( sprintf ' E<%s#%d>', __PACKAGE__, $_ ) ) } 1 .. 3 } );
  3         34  
  3         9  
  9         215  
20              
21             {
22 3     3   20 no strict 'refs'; # namespace clean
  3         4  
  3         1032  
23             delete ${ __PACKAGE__ . q[::] }{ sprintf '_E%x', $_ } for 1 .. 3;
24             }
25              
26              
27              
28              
29              
30              
31              
32              
33              
34              
35              
36             sub new {
37 2     2 1 7 my ( $class, @args ) = @_;
38 2 50       11 my (%args) = ref $args[0] ? %{ $args[0] } : @args;
  0         0  
39 2         11 return bless \%args, $class;
40             }
41              
42              
43              
44              
45              
46              
47              
48              
49              
50              
51              
52              
53             sub new_from_ARGV {
54 2 50   2 1 30 my (@args) = defined $_[1] ? @{ $_[1] } : @ARGV;
  2         8  
55 2         4 my $module;
56             my @load_modules;
57 2         7 while ( @args ) {
58 3         6 my $argument = shift @args;
59 3 100 33     23 if ( not defined $module and $argument !~ /\A-/sx ) {
60 2         4 $module = $argument;
61 2         7 next;
62             }
63 1 50       7 if( $argument =~ /\A-M(.*)\z/sx ) {
64 1         5 push @load_modules, $1;
65 1         2 next;
66             }
67 0         0 croak 'Unexpected argument ' . $argument . _E3;
68             }
69 2 50       6 defined $module or croak 'Expected a module name, got none' . _E1;
70 2 100       16 return $_[0]->new( module => $module, load_modules => [ @load_modules ? @load_modules : $module ] );
71             }
72              
73 0     0     sub _load_modules { return @{ $_[0]->{load_modules} } }
  0            
74 0     0     sub _module { return $_[0]->{module} }
75 0   0 0     sub _output { return ( $_[0]->{output} || *STDOUT ) }
76              
77              
78              
79              
80              
81              
82              
83             sub run {
84 0     0 1   my ($self) = @_;
85 0           load $_ for $self->_load_modules;
86             croak "Could not print to output handle: $! $^E" . _E2
87 0 0         unless print { $self->_output } explain_isa( $self->_module );
  0            
88              
89 0           return 0;
90             }
91              
92             1;
93              
94             __END__