line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CLI::Driver::Option; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
136
|
use Modern::Perl; |
|
18
|
|
|
|
|
40
|
|
|
18
|
|
|
|
|
136
|
|
4
|
18
|
|
|
18
|
|
2597
|
use Moose; |
|
18
|
|
|
|
|
38
|
|
|
18
|
|
|
|
|
119
|
|
5
|
18
|
|
|
18
|
|
121141
|
use namespace::autoclean; |
|
18
|
|
|
|
|
43
|
|
|
18
|
|
|
|
|
161
|
|
6
|
18
|
|
|
18
|
|
1410
|
use Kavorka '-all'; |
|
18
|
|
|
|
|
42
|
|
|
18
|
|
|
|
|
482
|
|
7
|
18
|
|
|
18
|
|
68868
|
use Data::Printer alias => 'pdump'; |
|
18
|
|
|
|
|
50
|
|
|
18
|
|
|
|
|
174
|
|
8
|
18
|
|
|
18
|
|
1595
|
use CLI::Driver::Deprecated; |
|
18
|
|
|
|
|
65
|
|
|
18
|
|
|
|
|
1064
|
|
9
|
|
|
|
|
|
|
|
10
|
18
|
|
|
18
|
|
16057
|
use Getopt::Long 'GetOptionsFromArray'; |
|
18
|
|
|
|
|
248986
|
|
|
18
|
|
|
|
|
91
|
|
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
|
|
35369
|
method get_signature { |
|
18
|
|
|
68
|
|
38
|
|
|
18
|
|
|
|
|
3431
|
|
|
68
|
|
|
|
|
234
|
|
|
68
|
|
|
|
|
112
|
|
65
|
|
|
|
|
|
|
|
66
|
68
|
|
|
|
|
113
|
my %sig; |
67
|
|
|
|
|
|
|
|
68
|
68
|
|
|
|
|
229
|
my $val = $self->_get_val; |
69
|
68
|
|
|
|
|
2099
|
$self->value($val); |
70
|
68
|
100
|
|
|
|
163
|
if ( defined $val ) { |
71
|
49
|
|
|
|
|
1275
|
$sig{ $self->method_arg } = $val; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
68
|
|
|
|
|
371
|
return %sig; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
18
|
50
|
|
18
|
|
20678
|
method is_required { |
|
18
|
|
|
35
|
|
58
|
|
|
18
|
|
|
|
|
2563
|
|
|
35
|
|
|
|
|
101
|
|
|
35
|
|
|
|
|
59
|
|
78
|
|
|
|
|
|
|
|
79
|
35
|
100
|
|
|
|
963
|
if ( $self->required ) { |
80
|
20
|
|
|
|
|
105
|
return 1; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
15
|
|
|
|
|
69
|
return 0; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
18
|
50
|
|
18
|
|
19818
|
method is_flag { |
|
18
|
|
|
68
|
|
65
|
|
|
18
|
|
|
|
|
2640
|
|
|
68
|
|
|
|
|
185
|
|
|
68
|
|
|
|
|
99
|
|
87
|
|
|
|
|
|
|
|
88
|
68
|
100
|
|
|
|
2214
|
if ( $self->flag ) { |
89
|
4
|
|
|
|
|
35
|
return 1; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
64
|
|
|
|
|
169
|
return 0; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
18
|
0
|
|
18
|
|
20411
|
method is_optional { |
|
18
|
|
|
0
|
|
43
|
|
|
18
|
|
|
|
|
2350
|
|
|
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
|
|
19369
|
method is_hard { |
|
18
|
|
|
8
|
|
50
|
|
|
18
|
|
|
|
|
2504
|
|
|
8
|
|
|
|
|
37
|
|
|
8
|
|
|
|
|
17
|
|
105
|
|
|
|
|
|
|
|
106
|
8
|
100
|
|
|
|
233
|
if ( $self->hard ) { |
107
|
5
|
|
|
|
|
31
|
return 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
27
|
return 0; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
18
|
50
|
|
18
|
|
19487
|
method is_soft { |
|
18
|
|
|
16
|
|
59
|
|
|
18
|
|
|
|
|
2466
|
|
|
16
|
|
|
|
|
57
|
|
|
16
|
|
|
|
|
33
|
|
114
|
|
|
|
|
|
|
|
115
|
16
|
100
|
|
|
|
397
|
if ( !$self->hard ) { |
116
|
2
|
|
|
|
|
9
|
return 1; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
14
|
|
|
|
|
88
|
return 0; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
18
|
0
|
|
18
|
|
339910
|
method get_usage (Str $dash_opt) { |
|
18
|
0
|
|
18
|
|
43
|
|
|
18
|
0
|
|
0
|
|
2772
|
|
|
18
|
0
|
|
|
|
137
|
|
|
18
|
0
|
|
|
|
63
|
|
|
18
|
|
|
|
|
4094
|
|
|
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
|
|
22210
|
method _get_val { |
|
18
|
|
|
68
|
|
49
|
|
|
18
|
|
|
|
|
10831
|
|
|
68
|
|
|
|
|
196
|
|
|
68
|
|
|
|
|
112
|
|
138
|
|
|
|
|
|
|
|
139
|
68
|
|
|
|
|
2078
|
my $arg = $self->cli_arg; |
140
|
68
|
|
|
|
|
129
|
my $val; |
141
|
|
|
|
|
|
|
|
142
|
68
|
100
|
|
|
|
203
|
if ( $self->is_flag ) { |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# - just a cli switch |
145
|
|
|
|
|
|
|
# - never required from cmdline |
146
|
|
|
|
|
|
|
|
147
|
4
|
50
|
|
|
|
116
|
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
|
|
|
|
|
35
|
my $success = GetOptionsFromArray( \@ARGV, "$arg" => \$val, ); |
154
|
4
|
50
|
|
|
|
1072
|
if ($success) { |
155
|
4
|
100
|
|
|
|
17
|
return $val ? 1 : 0; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
0
|
confess "something went sideways?"; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
else { |
162
|
|
|
|
|
|
|
|
163
|
64
|
100
|
|
|
|
1675
|
if ( $self->use_argv_map ) { |
164
|
4
|
50
|
|
|
|
109
|
if ( $ARGV{ $self->method_arg } ) { |
165
|
4
|
|
|
|
|
102
|
$val = $ARGV{ $self->method_arg }; |
166
|
4
|
|
|
|
|
100
|
delete $ARGV{ $self->method_arg }; |
167
|
4
|
|
|
|
|
14
|
return $val; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else { |
171
|
|
|
|
|
|
|
# get "-arg <val>" from cmdline if exists |
172
|
60
|
|
|
|
|
121
|
my $arg_type = "s"; |
173
|
60
|
100
|
|
|
|
1481
|
$arg_type .= '@' if $self->is_array; |
174
|
|
|
|
|
|
|
|
175
|
60
|
|
|
|
|
399
|
my $success = |
176
|
|
|
|
|
|
|
GetOptionsFromArray( \@ARGV, "$arg=$arg_type" => \$val, ); |
177
|
60
|
50
|
|
|
|
16402
|
if ($success) { |
178
|
60
|
|
|
|
|
189
|
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; |