File Coverage

blib/lib/YA/CLI/Usage.pm
Criterion Covered Total %
statement 23 28 82.1
branch 8 10 80.0
condition 0 2 0.0
subroutine 7 9 77.7
pod 1 1 100.0
total 39 50 78.0


line stmt bran cond sub pod time code
1             package YA::CLI::Usage;
2             our $VERSION = '0.007';
3 8     8   211547 use Moo;
  8         15254  
  8         57  
4 8     8   7848 use namespace::autoclean;
  8         20561  
  8         58  
5              
6             # ABSTRACT: Class that handles usage and man page generation for action handlers
7              
8 8     8   668 use Carp qw(croak);
  8         15  
  8         517  
9 8     8   44 use List::Util qw(first);
  8         14  
  8         524  
10 8     8   41 use Pod::Find qw(pod_where);
  8         12  
  8         405  
11 8     8   4980 use Pod::Usage qw(pod2usage);
  8         511764  
  8         3299  
12              
13             has verbose => (
14             is => 'rw',
15             default => 1,
16             );
17              
18             has rc => (
19             is => 'ro',
20             default => 0,
21             );
22              
23             has message => (
24             is => 'ro',
25             predicate => 'has_message',
26             );
27              
28             has pod_file => (
29             is => 'ro',
30             predicate => 'has_pod_file'
31             );
32              
33             sub run {
34 10     10 1 1260 my $self = shift;
35              
36 10         32 my $pod_where = $self->_pod_where;
37              
38 10 100       84 if ($self->verbose == 1) {
39 8         16 $self->verbose(99);
40             }
41              
42             $self->_pod2usage(
43 10 100       106 $self->has_message ? (-message => $self->message) : (),
    100          
    100          
44             -verbose => $self->verbose,
45             -exitval => $self->rc,
46             $self->verbose == 99 ? ( -sections => 'NAME|SYNOPSIS|COMMANDS|OPTIONS' ) : (),
47             $pod_where ? ('-input' => $pod_where) : (),
48             );
49             }
50              
51             sub _pod_where {
52 0     0     my $self = shift;
53 0 0         return unless $self->has_pod_file;
54 0   0       return pod_where({ -inc => 1, -verbose => $ENV{YA_CLI_USAGE_LIB} // 0 }, $self->pod_file);
55             }
56              
57             sub _pod2usage {
58 0     0     my $self = shift;
59 0           pod2usage(@_);
60             }
61              
62             __PACKAGE__->meta->make_immutable;
63              
64             __END__