line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CLI::Driver::Option; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
124
|
use Modern::Perl; |
|
18
|
|
|
|
|
38
|
|
|
18
|
|
|
|
|
127
|
|
4
|
18
|
|
|
18
|
|
2362
|
use Moose; |
|
18
|
|
|
|
|
33
|
|
|
18
|
|
|
|
|
98
|
|
5
|
18
|
|
|
18
|
|
109808
|
use namespace::autoclean; |
|
18
|
|
|
|
|
40
|
|
|
18
|
|
|
|
|
140
|
|
6
|
18
|
|
|
18
|
|
1313
|
use Kavorka '-all'; |
|
18
|
|
|
|
|
41
|
|
|
18
|
|
|
|
|
398
|
|
7
|
18
|
|
|
18
|
|
63141
|
use Data::Printer alias => 'pdump'; |
|
18
|
|
|
|
|
43
|
|
|
18
|
|
|
|
|
144
|
|
8
|
18
|
|
|
18
|
|
1475
|
use CLI::Driver::Deprecated; |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
911
|
|
9
|
|
|
|
|
|
|
|
10
|
18
|
|
|
18
|
|
14233
|
use Getopt::Long 'GetOptionsFromArray'; |
|
18
|
|
|
|
|
225610
|
|
|
18
|
|
|
|
|
89
|
|
11
|
|
|
|
|
|
|
Getopt::Long::Configure('no_ignore_case'); |
12
|
|
|
|
|
|
|
Getopt::Long::Configure('pass_through'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'CLI::Driver::CommonRole'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
############################### |
17
|
|
|
|
|
|
|
###### PUBLIC ATTRIBUTES ###### |
18
|
|
|
|
|
|
|
############################### |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has class => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
isa => 'Str', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has cli_arg => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
isa => 'Str' |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has method_arg => ( |
31
|
|
|
|
|
|
|
is => 'rw', |
32
|
|
|
|
|
|
|
isa => 'Str|Undef' |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has required => ( |
36
|
|
|
|
|
|
|
is => 'rw', |
37
|
|
|
|
|
|
|
isa => 'Bool' |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has hard => ( |
41
|
|
|
|
|
|
|
is => 'rw', |
42
|
|
|
|
|
|
|
isa => 'Bool', |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has flag => ( |
46
|
|
|
|
|
|
|
is => 'rw', |
47
|
|
|
|
|
|
|
isa => 'Bool', |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has is_array => ( |
51
|
|
|
|
|
|
|
is => 'rw', |
52
|
|
|
|
|
|
|
isa => 'Bool', |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
has value => ( |
56
|
|
|
|
|
|
|
is => 'rw', |
57
|
|
|
|
|
|
|
isa => 'Any', |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
has 'use_argv_map' => ( is => 'rw', isa => 'Bool' ); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
############################################### |
63
|
|
|
|
|
|
|
|
64
|
18
|
50
|
|
18
|
|
31735
|
method get_signature { |
|
18
|
|
|
70
|
|
38
|
|
|
18
|
|
|
|
|
2993
|
|
|
70
|
|
|
|
|
245
|
|
|
70
|
|
|
|
|
107
|
|
65
|
|
|
|
|
|
|
|
66
|
70
|
|
|
|
|
126
|
my %sig; |
67
|
|
|
|
|
|
|
|
68
|
70
|
|
|
|
|
253
|
my $val = $self->_get_val; |
69
|
70
|
|
|
|
|
2039
|
$self->value($val); |
70
|
70
|
100
|
|
|
|
174
|
if ( defined $val ) { |
71
|
49
|
|
|
|
|
1289
|
$sig{ $self->method_arg } = $val; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
70
|
|
|
|
|
347
|
return %sig; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
18
|
50
|
|
18
|
|
18698
|
method is_required { |
|
18
|
|
|
36
|
|
56
|
|
|
18
|
|
|
|
|
2247
|
|
|
36
|
|
|
|
|
137
|
|
|
36
|
|
|
|
|
58
|
|
78
|
|
|
|
|
|
|
|
79
|
36
|
100
|
|
|
|
929
|
if ( $self->required ) { |
80
|
20
|
|
|
|
|
97
|
return 1; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
16
|
|
|
|
|
80
|
return 0; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
18
|
50
|
|
18
|
|
17627
|
method is_flag { |
|
18
|
|
|
70
|
|
54
|
|
|
18
|
|
|
|
|
2303
|
|
|
70
|
|
|
|
|
181
|
|
|
70
|
|
|
|
|
111
|
|
87
|
|
|
|
|
|
|
|
88
|
70
|
100
|
|
|
|
2099
|
if ( $self->flag ) { |
89
|
4
|
|
|
|
|
16
|
return 1; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
66
|
|
|
|
|
182
|
return 0; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
18
|
0
|
|
18
|
|
18481
|
method is_optional { |
|
18
|
|
|
0
|
|
50
|
|
|
18
|
|
|
|
|
2406
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
0
|
if ( !$self->required ) { |
98
|
0
|
|
|
|
|
0
|
return 1; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
0
|
return 0; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
18
|
50
|
|
18
|
|
17820
|
method is_hard { |
|
18
|
|
|
9
|
|
47
|
|
|
18
|
|
|
|
|
2292
|
|
|
9
|
|
|
|
|
38
|
|
|
9
|
|
|
|
|
17
|
|
105
|
|
|
|
|
|
|
|
106
|
9
|
100
|
|
|
|
231
|
if ( $self->hard ) { |
107
|
5
|
|
|
|
|
30
|
return 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
4
|
|
|
|
|
23
|
return 0; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
18
|
50
|
|
18
|
|
17650
|
method is_soft { |
|
18
|
|
|
16
|
|
67
|
|
|
18
|
|
|
|
|
2046
|
|
|
16
|
|
|
|
|
56
|
|
|
16
|
|
|
|
|
34
|
|
114
|
|
|
|
|
|
|
|
115
|
16
|
100
|
|
|
|
481
|
if ( !$self->hard ) { |
116
|
2
|
|
|
|
|
9
|
return 1; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
14
|
|
|
|
|
93
|
return 0; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
18
|
0
|
|
18
|
|
304134
|
method get_usage (Str $dash_opt) { |
|
18
|
0
|
|
18
|
|
43
|
|
|
18
|
0
|
|
0
|
|
2423
|
|
|
18
|
0
|
|
|
|
135
|
|
|
18
|
0
|
|
|
|
109
|
|
|
18
|
|
|
|
|
3614
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
0
|
if ($self->is_flag) { |
125
|
0
|
|
|
|
|
0
|
return sprintf '--%s', $dash_opt; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
0
|
my @out; |
129
|
0
|
|
|
|
|
0
|
push @out, sprintf '-%s', $dash_opt; |
130
|
0
|
|
|
|
|
0
|
push @out, sprintf '<%s>', $self->method_arg; |
131
|
0
|
0
|
|
|
|
0
|
push @out, '(soft)' if $self->is_soft; |
132
|
0
|
0
|
|
|
|
0
|
push @out, '(multi)' if $self->is_array; |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
0
|
return join( ' ', @out ); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
18
|
50
|
|
18
|
|
19774
|
method _get_val { |
|
18
|
|
|
70
|
|
39
|
|
|
18
|
|
|
|
|
9727
|
|
|
70
|
|
|
|
|
221
|
|
|
70
|
|
|
|
|
118
|
|
138
|
|
|
|
|
|
|
|
139
|
70
|
|
|
|
|
1900
|
my $arg = $self->cli_arg; |
140
|
70
|
|
|
|
|
155
|
my $val; |
141
|
|
|
|
|
|
|
|
142
|
70
|
100
|
|
|
|
218
|
if ( $self->is_flag ) { |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# - just a cli switch |
145
|
|
|
|
|
|
|
# - never required from cmdline |
146
|
|
|
|
|
|
|
|
147
|
4
|
50
|
|
|
|
107
|
if ( $self->use_argv_map ) { |
148
|
0
|
|
|
|
|
0
|
$val = $ARGV{ $self->method_arg }; |
149
|
0
|
|
|
|
|
0
|
delete $ARGV{ $self->method_arg }; |
150
|
0
|
|
|
|
|
0
|
return $val; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
else { |
153
|
4
|
|
|
|
|
34
|
my $success = GetOptionsFromArray( \@ARGV, "$arg" => \$val, ); |
154
|
4
|
50
|
|
|
|
1291
|
if ($success) { |
155
|
4
|
100
|
|
|
|
18
|
return $val ? 1 : 0; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
0
|
confess "something went sideways?"; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
else { |
162
|
|
|
|
|
|
|
|
163
|
66
|
100
|
|
|
|
1667
|
if ( $self->use_argv_map ) { |
164
|
4
|
50
|
|
|
|
87
|
if ( $ARGV{ $self->method_arg } ) { |
165
|
4
|
|
|
|
|
80
|
$val = $ARGV{ $self->method_arg }; |
166
|
4
|
|
|
|
|
80
|
delete $ARGV{ $self->method_arg }; |
167
|
4
|
|
|
|
|
11
|
return $val; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else { |
171
|
|
|
|
|
|
|
# get "-arg <val>" from cmdline if exists |
172
|
62
|
|
|
|
|
121
|
my $arg_type = "s"; |
173
|
62
|
100
|
|
|
|
1454
|
$arg_type .= '@' if $self->is_array; |
174
|
|
|
|
|
|
|
|
175
|
62
|
|
|
|
|
381
|
my $success = |
176
|
|
|
|
|
|
|
GetOptionsFromArray( \@ARGV, "$arg=$arg_type" => \$val, ); |
177
|
62
|
50
|
|
|
|
16479
|
if ($success) { |
178
|
62
|
|
|
|
|
186
|
return $val; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
|
confess "something went sideways?" if !$success; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# we didn't find it in @ARGV |
185
|
0
|
0
|
0
|
|
|
|
if ( $self->is_hard && $self->required ) { |
186
|
0
|
|
|
|
|
|
confess "failed to get arg from argv: $arg"; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
return; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; |