line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Commando::Option; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
22705
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
193
|
|
4
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
160
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
823
|
use Moo; |
|
5
|
|
|
|
|
26201
|
|
|
5
|
|
|
|
|
39
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'config_key' => ( is => 'ro' ); |
9
|
|
|
|
|
|
|
has 'description' => ( is => 'ro' ); |
10
|
|
|
|
|
|
|
has 'long' => ( is => 'ro' ); |
11
|
|
|
|
|
|
|
has 'short' => ( is => 'ro' ); |
12
|
|
|
|
|
|
|
has 'spec' => ( is => 'ro' ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub BUILDARGS { |
15
|
41
|
|
|
41
|
0
|
10408
|
my ($class, $config_key, @info) = @_; |
16
|
|
|
|
|
|
|
|
17
|
41
|
|
|
|
|
128
|
my $buildargs = { |
18
|
|
|
|
|
|
|
config_key => $config_key, |
19
|
|
|
|
|
|
|
long => '', |
20
|
|
|
|
|
|
|
short => '', |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Getopt::Long regular expression to match argument specification |
24
|
41
|
|
|
|
|
127
|
my $spec_re = qr( |
25
|
|
|
|
|
|
|
# Either modifiers ... |
26
|
|
|
|
|
|
|
[!+] |
27
|
|
|
|
|
|
|
| |
28
|
|
|
|
|
|
|
# ... or a value/dest/repeat specification |
29
|
|
|
|
|
|
|
[=:] [ionfs] [@%]? (?: \{\d*,?\d*\} )? |
30
|
|
|
|
|
|
|
| |
31
|
|
|
|
|
|
|
# ... or an optional-with-default spec |
32
|
|
|
|
|
|
|
: (?: -?\d+ | \+ ) [@%]? |
33
|
|
|
|
|
|
|
)x; |
34
|
|
|
|
|
|
|
|
35
|
41
|
|
|
|
|
73
|
for my $arg (@info) { |
36
|
122
|
100
|
|
|
|
694
|
if ($arg =~ /^-/) { |
|
|
100
|
|
|
|
|
|
37
|
78
|
100
|
|
|
|
159
|
if ($arg =~ /^--/) { |
38
|
39
|
|
|
|
|
69
|
$buildargs->{long} = $arg; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
39
|
|
|
|
|
74
|
$buildargs->{short} = $arg; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif ($arg =~ $spec_re) { |
45
|
4
|
|
|
|
|
13
|
$buildargs->{spec} = $arg; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
40
|
|
|
|
|
101
|
$buildargs->{description} = $arg; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
41
|
|
|
|
|
1047
|
return $buildargs; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub for_get_options { |
56
|
69
|
|
|
69
|
0
|
953
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return |
59
|
138
|
|
|
|
|
789
|
join('|', |
60
|
138
|
|
|
|
|
350
|
grep { /\S/ } # Exclude empty strings |
61
|
138
|
|
|
|
|
253
|
map { s/^-+//; $_ } # Strip off leading dashes |
|
138
|
|
|
|
|
311
|
|
62
|
69
|
|
100
|
|
|
91
|
map { $self->$_ } qw( short long )) . |
63
|
|
|
|
|
|
|
($self->spec || ''); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub switches { |
67
|
19
|
|
|
19
|
0
|
73
|
my ($self) = @_; |
68
|
|
|
|
|
|
|
|
69
|
19
|
|
|
|
|
113
|
return [ $self->short, $self->long ]; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub formatted_switches { |
73
|
8
|
|
|
8
|
0
|
14
|
my ($self) = @_; |
74
|
|
|
|
|
|
|
|
75
|
8
|
|
|
|
|
21
|
my $output = join(', ', |
76
|
|
|
|
|
|
|
sprintf("%10s", $self->switches->[0]), |
77
|
|
|
|
|
|
|
sprintf("%-13s", $self->switches->[-1])); |
78
|
8
|
|
|
|
|
27
|
$output =~ s/ , / /g; |
79
|
8
|
|
|
|
|
16
|
$output =~ s/, / /g; |
80
|
|
|
|
|
|
|
|
81
|
8
|
|
|
|
|
53
|
return $output; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub as_string { |
85
|
5
|
|
|
5
|
0
|
9
|
my ($self) = @_; |
86
|
|
|
|
|
|
|
|
87
|
5
|
|
|
|
|
13
|
return $self->formatted_switches . ' ' . $self->description; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |