| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MooX::Role::CliOptions; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
68609
|
use 5.006; |
|
|
4
|
|
|
|
|
16
|
|
|
4
|
4
|
|
|
4
|
|
22
|
use strict; |
|
|
4
|
|
|
|
|
12
|
|
|
|
4
|
|
|
|
|
77
|
|
|
5
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
106
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
28
|
use Carp qw( croak ); |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
253
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
2965
|
use Getopt::Long v2.36 qw(GetOptionsFromArray); |
|
|
4
|
|
|
|
|
44586
|
|
|
|
4
|
|
|
|
|
103
|
|
|
10
|
4
|
|
|
4
|
|
2915
|
use Pod::Usage; |
|
|
4
|
|
|
|
|
200555
|
|
|
|
4
|
|
|
|
|
487
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# this could have been replaced with hand-rolled "isa" clauses, but if |
|
13
|
|
|
|
|
|
|
# one is using Moo then the odds are good that one already has this |
|
14
|
4
|
|
|
4
|
|
2341
|
use Types::Standard qw( ArrayRef Bool ); |
|
|
4
|
|
|
|
|
332376
|
|
|
|
4
|
|
|
|
|
54
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
4376
|
use Moo::Role; |
|
|
4
|
|
|
|
|
16564
|
|
|
|
4
|
|
|
|
|
35
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.04.1_004'; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my @options = ( 'help', 'man' ); |
|
21
|
|
|
|
|
|
|
do { |
|
22
|
|
|
|
|
|
|
has debug => ( |
|
23
|
|
|
|
|
|
|
is => 'ro', |
|
24
|
|
|
|
|
|
|
isa => Bool, |
|
25
|
|
|
|
|
|
|
default => 1, |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has verbose => ( |
|
29
|
|
|
|
|
|
|
is => 'ro', |
|
30
|
|
|
|
|
|
|
isa => Bool, |
|
31
|
|
|
|
|
|
|
default => 1, |
|
32
|
|
|
|
|
|
|
); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
push( @options, qw( debug! verbose! ) ); |
|
35
|
|
|
|
|
|
|
} unless $ENV{MRC_NO_STDOPTS}; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has argv => ( |
|
38
|
|
|
|
|
|
|
is => 'ro', |
|
39
|
|
|
|
|
|
|
isa => ArrayRef, |
|
40
|
|
|
|
|
|
|
); |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub init { |
|
43
|
25
|
|
|
25
|
1
|
65268
|
my $class = shift; |
|
44
|
25
|
|
|
|
|
71
|
my %args = @_; |
|
45
|
|
|
|
|
|
|
|
|
46
|
25
|
50
|
|
|
|
90
|
my $argv = delete( $args{argv} ) or croak q{'argv' argument is required}; |
|
47
|
25
|
50
|
33
|
|
|
183
|
croak q{'argv' must be an array reference'} |
|
48
|
|
|
|
|
|
|
unless ref($argv) && ref($argv) eq 'ARRAY'; |
|
49
|
|
|
|
|
|
|
|
|
50
|
25
|
|
100
|
|
|
81
|
my $add_opts = delete( $args{add_opts} ) || []; |
|
51
|
25
|
50
|
33
|
|
|
97
|
croak q{'add_opts' must be an array reference'} |
|
52
|
|
|
|
|
|
|
unless ref($add_opts) && ref($add_opts) eq 'ARRAY'; |
|
53
|
|
|
|
|
|
|
|
|
54
|
25
|
50
|
|
|
|
72
|
croak q{unknown argument supplied for 'init'} if keys(%args); |
|
55
|
|
|
|
|
|
|
|
|
56
|
25
|
|
|
|
|
34
|
push( @options, $_ ) for ( @{$add_opts} ); |
|
|
25
|
|
|
|
|
66
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
25
|
|
|
|
|
52
|
my %values; |
|
59
|
25
|
100
|
|
|
|
87
|
GetOptionsFromArray( $argv, \%values, @options ) or _pod2usage(2); |
|
60
|
25
|
50
|
|
|
|
8638
|
_pod2usage(1) if $values{help}; |
|
61
|
25
|
50
|
|
|
|
55
|
_pod2usage( -exitstatus => 0, -verbose => 2 ) if $values{man}; |
|
62
|
|
|
|
|
|
|
|
|
63
|
25
|
|
|
|
|
46
|
$values{argv} = $argv; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
do { |
|
66
|
|
|
|
|
|
|
# have (no)debug imply verbose if that is not not specificed. |
|
67
|
|
|
|
|
|
|
# This is a # personal preference based on my experience of how |
|
68
|
|
|
|
|
|
|
# these options are most commonly used. |
|
69
|
|
|
|
|
|
|
$values{verbose} ||= $values{debug} |
|
70
|
16
|
100
|
66
|
|
|
62
|
if defined( $values{debug} ) && !defined( $values{verbose} ); |
|
|
|
|
100
|
|
|
|
|
|
71
|
25
|
100
|
|
|
|
68
|
} unless $ENV{MRC_NO_STDOPTS}; |
|
72
|
|
|
|
|
|
|
|
|
73
|
25
|
|
|
|
|
45
|
my $app = eval { $class->new(%values); }; |
|
|
25
|
|
|
|
|
581
|
|
|
74
|
25
|
50
|
|
|
|
6890
|
do { |
|
75
|
0
|
|
|
|
|
0
|
print $@ . "\n"; |
|
76
|
0
|
|
|
|
|
0
|
_pod2usage(2); |
|
77
|
|
|
|
|
|
|
} if $@; |
|
78
|
|
|
|
|
|
|
|
|
79
|
25
|
|
|
|
|
155
|
return $app; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# this is needed so test scripts can intercept the call to pod2usage and |
|
83
|
|
|
|
|
|
|
# prevent the exit from happening |
|
84
|
|
|
|
|
|
|
sub _pod2usage { |
|
85
|
0
|
|
|
0
|
|
|
pod2usage(@_); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; # End of MooX::Role::CliOptions |
|
89
|
|
|
|
|
|
|
__END__ |