line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CLI::Driver::Option; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
145
|
use Modern::Perl; |
|
18
|
|
|
|
|
41
|
|
|
18
|
|
|
|
|
141
|
|
4
|
18
|
|
|
18
|
|
2640
|
use Moose; |
|
18
|
|
|
|
|
38
|
|
|
18
|
|
|
|
|
137
|
|
5
|
18
|
|
|
18
|
|
123202
|
use namespace::autoclean; |
|
18
|
|
|
|
|
55
|
|
|
18
|
|
|
|
|
151
|
|
6
|
18
|
|
|
18
|
|
1442
|
use Kavorka '-all'; |
|
18
|
|
|
|
|
40
|
|
|
18
|
|
|
|
|
421
|
|
7
|
18
|
|
|
18
|
|
69775
|
use Data::Printer alias => 'pdump'; |
|
18
|
|
|
|
|
48
|
|
|
18
|
|
|
|
|
154
|
|
8
|
18
|
|
|
18
|
|
1600
|
use CLI::Driver::Deprecated; |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
1076
|
|
9
|
|
|
|
|
|
|
|
10
|
18
|
|
|
18
|
|
16123
|
use Getopt::Long 'GetOptionsFromArray'; |
|
18
|
|
|
|
|
253212
|
|
|
18
|
|
|
|
|
104
|
|
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
|
|
35773
|
method get_signature { |
|
18
|
|
|
68
|
|
49
|
|
|
18
|
|
|
|
|
3522
|
|
|
68
|
|
|
|
|
199
|
|
|
68
|
|
|
|
|
102
|
|
65
|
|
|
|
|
|
|
|
66
|
68
|
|
|
|
|
117
|
my %sig; |
67
|
|
|
|
|
|
|
|
68
|
68
|
|
|
|
|
215
|
my $val = $self->_get_val; |
69
|
68
|
|
|
|
|
2259
|
$self->value($val); |
70
|
68
|
100
|
|
|
|
176
|
if ( defined $val ) { |
71
|
49
|
|
|
|
|
1458
|
$sig{ $self->method_arg } = $val; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
68
|
|
|
|
|
344
|
return %sig; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
18
|
50
|
|
18
|
|
21146
|
method is_required { |
|
18
|
|
|
35
|
|
56
|
|
|
18
|
|
|
|
|
2598
|
|
|
35
|
|
|
|
|
104
|
|
|
35
|
|
|
|
|
59
|
|
78
|
|
|
|
|
|
|
|
79
|
35
|
100
|
|
|
|
954
|
if ( $self->required ) { |
80
|
20
|
|
|
|
|
110
|
return 1; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
15
|
|
|
|
|
68
|
return 0; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
18
|
50
|
|
18
|
|
20250
|
method is_flag { |
|
18
|
|
|
68
|
|
72
|
|
|
18
|
|
|
|
|
2653
|
|
|
68
|
|
|
|
|
209
|
|
|
68
|
|
|
|
|
108
|
|
87
|
|
|
|
|
|
|
|
88
|
68
|
100
|
|
|
|
2283
|
if ( $self->flag ) { |
89
|
4
|
|
|
|
|
17
|
return 1; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
64
|
|
|
|
|
178
|
return 0; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
18
|
0
|
|
18
|
|
20746
|
method is_optional { |
|
18
|
|
|
0
|
|
56
|
|
|
18
|
|
|
|
|
2401
|
|
|
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
|
|
19926
|
method is_hard { |
|
18
|
|
|
8
|
|
51
|
|
|
18
|
|
|
|
|
2534
|
|
|
8
|
|
|
|
|
38
|
|
|
8
|
|
|
|
|
16
|
|
105
|
|
|
|
|
|
|
|
106
|
8
|
100
|
|
|
|
224
|
if ( $self->hard ) { |
107
|
5
|
|
|
|
|
33
|
return 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
19
|
return 0; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
18
|
50
|
|
18
|
|
20162
|
method is_soft { |
|
18
|
|
|
16
|
|
66
|
|
|
18
|
|
|
|
|
2446
|
|
|
16
|
|
|
|
|
57
|
|
|
16
|
|
|
|
|
31
|
|
114
|
|
|
|
|
|
|
|
115
|
16
|
100
|
|
|
|
420
|
if ( !$self->hard ) { |
116
|
2
|
|
|
|
|
17
|
return 1; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
14
|
|
|
|
|
87
|
return 0; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
18
|
0
|
|
18
|
|
345441
|
method get_usage (Str $dash_opt) { |
|
18
|
0
|
|
18
|
|
41
|
|
|
18
|
0
|
|
0
|
|
2778
|
|
|
18
|
0
|
|
|
|
139
|
|
|
18
|
0
|
|
|
|
66
|
|
|
18
|
|
|
|
|
4048
|
|
|
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
|
|
23067
|
method _get_val { |
|
18
|
|
|
68
|
|
60
|
|
|
18
|
|
|
|
|
11222
|
|
|
68
|
|
|
|
|
186
|
|
|
68
|
|
|
|
|
132
|
|
138
|
|
|
|
|
|
|
|
139
|
68
|
|
|
|
|
2055
|
my $arg = $self->cli_arg; |
140
|
68
|
|
|
|
|
129
|
my $val; |
141
|
|
|
|
|
|
|
|
142
|
68
|
100
|
|
|
|
219
|
if ( $self->is_flag ) { |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# - just a cli switch |
145
|
|
|
|
|
|
|
# - never required from cmdline |
146
|
|
|
|
|
|
|
|
147
|
4
|
50
|
|
|
|
114
|
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
|
|
|
|
|
31
|
my $success = GetOptionsFromArray( \@ARGV, "$arg" => \$val, ); |
154
|
4
|
50
|
|
|
|
1430
|
if ($success) { |
155
|
4
|
100
|
|
|
|
23
|
return $val ? 1 : 0; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
0
|
confess "something went sideways?"; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
else { |
162
|
|
|
|
|
|
|
|
163
|
64
|
100
|
|
|
|
1692
|
if ( $self->use_argv_map ) { |
164
|
4
|
50
|
|
|
|
100
|
if ( $ARGV{ $self->method_arg } ) { |
165
|
4
|
|
|
|
|
151
|
$val = $ARGV{ $self->method_arg }; |
166
|
4
|
|
|
|
|
104
|
delete $ARGV{ $self->method_arg }; |
167
|
4
|
|
|
|
|
12
|
return $val; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else { |
171
|
|
|
|
|
|
|
# get "-arg <val>" from cmdline if exists |
172
|
60
|
|
|
|
|
122
|
my $arg_type = "s"; |
173
|
60
|
100
|
|
|
|
1556
|
$arg_type .= '@' if $self->is_array; |
174
|
|
|
|
|
|
|
|
175
|
60
|
|
|
|
|
333
|
my $success = |
176
|
|
|
|
|
|
|
GetOptionsFromArray( \@ARGV, "$arg=$arg_type" => \$val, ); |
177
|
60
|
50
|
|
|
|
16303
|
if ($success) { |
178
|
60
|
|
|
|
|
199
|
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; |