line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::EX::Long; |
2
|
4
|
|
|
4
|
|
240273
|
use version; our $VERSION = version->declare("2.1.3"); |
|
4
|
|
|
|
|
6219
|
|
|
4
|
|
|
|
|
23
|
|
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
388
|
use v5.14; |
|
4
|
|
|
|
|
23
|
|
5
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
119
|
|
6
|
4
|
|
|
4
|
|
18
|
use Carp; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
573
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
*REQUIRE_ORDER = \$Getopt::Long::REQUIRE_ORDER; |
9
|
|
|
|
|
|
|
*PERMUTE = \$Getopt::Long::PERMUTE; |
10
|
|
|
|
|
|
|
*RETURN_IN_ORDER = \$Getopt::Long::RETURN_IN_ORDER; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
*Configure = \&Getopt::Long::Configure; |
13
|
|
|
|
|
|
|
*HelpMessage = \&Getopt::Long::HelpMessage; |
14
|
|
|
|
|
|
|
*VersionMessage = \&Getopt::Long::VersionMessage; |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
27
|
use Exporter 'import'; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
375
|
|
17
|
|
|
|
|
|
|
our @EXPORT = qw(&GetOptions $REQUIRE_ORDER $PERMUTE $RETURN_IN_ORDER); |
18
|
|
|
|
|
|
|
our @EXPORT_OK = ( '&GetOptionsFromArray', |
19
|
|
|
|
|
|
|
# '&GetOptionsFromString', |
20
|
|
|
|
|
|
|
'&Configure', |
21
|
|
|
|
|
|
|
'&HelpMessage', |
22
|
|
|
|
|
|
|
'&VersionMessage', |
23
|
|
|
|
|
|
|
'&ExConfigure', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
our @ISA = qw(Getopt::Long); |
26
|
|
|
|
|
|
|
|
27
|
4
|
|
|
4
|
|
26
|
use Data::Dumper; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
299
|
|
28
|
4
|
|
|
4
|
|
3406
|
use Getopt::Long(); |
|
4
|
|
|
|
|
50791
|
|
|
4
|
|
|
|
|
140
|
|
29
|
4
|
|
|
4
|
|
1392
|
use Getopt::EX::Loader; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
187
|
|
30
|
4
|
|
|
4
|
|
27
|
use Getopt::EX::Func qw(parse_func); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1294
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my %ConfigOption = ( AUTO_DEFAULT => 1 ); |
33
|
|
|
|
|
|
|
my @ValidOptions = ('AUTO_DEFAULT' , @Getopt::EX::Loader::OPTIONS); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $loader; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub GetOptions { |
38
|
2
|
|
|
2
|
1
|
10679
|
unshift @_, \@ARGV; |
39
|
2
|
|
|
|
|
17
|
goto &GetOptionsFromArray; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub GetOptionsFromArray { |
43
|
2
|
|
|
2
|
0
|
5
|
my $argv = $_[0]; |
44
|
|
|
|
|
|
|
|
45
|
2
|
50
|
|
|
|
15
|
set_default() if $ConfigOption{AUTO_DEFAULT}; |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
33
|
|
|
23
|
$loader //= Getopt::EX::Loader->new(do { |
48
|
|
|
|
|
|
|
map { |
49
|
2
|
100
|
|
|
|
6
|
exists $ConfigOption{$_} ? ( $_ => $ConfigOption{$_} ) : () |
|
12
|
|
|
|
|
51
|
|
50
|
|
|
|
|
|
|
} @Getopt::EX::Loader::OPTIONS |
51
|
|
|
|
|
|
|
}); |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
19
|
$loader->deal_with($argv); |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
20
|
my @builtins = do { |
56
|
2
|
100
|
|
|
|
22
|
if (ref $_[1] eq 'HASH') { |
57
|
1
|
|
|
|
|
6
|
$loader->hashed_builtins($_[1]); |
58
|
|
|
|
|
|
|
} else { |
59
|
1
|
|
|
|
|
11
|
$loader->builtins; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
}; |
62
|
2
|
|
|
|
|
21
|
push @_, @builtins; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
16
|
goto &Getopt::Long::GetOptionsFromArray; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub GetOptionsFromString { |
68
|
0
|
|
|
0
|
0
|
0
|
die "GetOptionsFromString is not supported, yet.\n"; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub ExConfigure { |
72
|
0
|
|
|
0
|
0
|
0
|
my %opt = @_; |
73
|
0
|
|
|
|
|
0
|
for my $name (@ValidOptions) { |
74
|
0
|
0
|
|
|
|
0
|
if (exists $opt{$name}) { |
75
|
0
|
|
|
|
|
0
|
$ConfigOption{$name} = delete $opt{$name}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
0
|
0
|
|
|
|
0
|
warn "Unknown option: ", Dumper \%opt if %opt; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub set_default { |
82
|
4
|
|
|
4
|
|
28
|
use List::Util qw(pairmap); |
|
4
|
|
|
|
|
63
|
|
|
4
|
|
|
|
|
985
|
|
83
|
3
|
|
33
|
3
|
0
|
29
|
pairmap { $ConfigOption{$a} //= $b } get_default(); |
|
2
|
|
|
2
|
|
14
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get_default { |
87
|
3
|
|
|
3
|
0
|
5
|
my @list; |
88
|
|
|
|
|
|
|
|
89
|
3
|
50
|
|
|
|
36
|
my $prog = ($0 =~ /([^\/]+)$/) ? $1 : return (); |
90
|
|
|
|
|
|
|
|
91
|
3
|
50
|
|
|
|
19
|
if (defined (my $home = $ENV{HOME})) { |
92
|
3
|
100
|
|
|
|
97
|
if (-f (my $rc = "$home/.${prog}rc")) { |
93
|
1
|
|
|
|
|
4
|
push @list, RCFILE => $rc; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
19
|
push @list, BASECLASS => "App::$prog"; |
98
|
|
|
|
|
|
|
|
99
|
3
|
|
|
|
|
42
|
@list; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
############################################################ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
package Getopt::EX::Long::Parser; |
107
|
|
|
|
|
|
|
|
108
|
4
|
|
|
4
|
|
46
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
141
|
|
109
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
166
|
|
110
|
|
|
|
|
|
|
|
111
|
4
|
|
|
4
|
|
22
|
use List::Util qw(first); |
|
4
|
|
|
|
|
31
|
|
|
4
|
|
|
|
|
270
|
|
112
|
4
|
|
|
4
|
|
26
|
use Data::Dumper; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
188
|
|
113
|
|
|
|
|
|
|
|
114
|
4
|
|
|
4
|
|
23
|
use Getopt::EX::Loader; |
|
4
|
|
|
|
|
19
|
|
|
4
|
|
|
|
|
1500
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
our @ISA = qw(Getopt::Long::Parser); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub new { |
119
|
1
|
|
|
1
|
|
196
|
my $class = shift; |
120
|
|
|
|
|
|
|
|
121
|
1
|
|
|
|
|
2
|
my @exconfig; |
122
|
1
|
|
|
0
|
|
15
|
while (defined (my $i = first { $_[$_] eq 'exconfig' } 0 .. $#_)) { |
|
0
|
|
|
|
|
0
|
|
123
|
0
|
|
|
|
|
0
|
push @exconfig, @{ (splice @_, $i, 2)[1] }; |
|
0
|
|
|
|
|
0
|
|
124
|
|
|
|
|
|
|
} |
125
|
1
|
50
|
33
|
|
|
10
|
if (@exconfig == 0 and $ConfigOption{AUTO_DEFAULT}) { |
126
|
1
|
|
|
|
|
19
|
@exconfig = Getopt::EX::Long::get_default(); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
11
|
my $obj = $class->SUPER::new(@_); |
130
|
|
|
|
|
|
|
|
131
|
1
|
|
|
|
|
28
|
my $loader = $obj->{exloader} = Getopt::EX::Loader->new(@exconfig); |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
|
|
3
|
$obj; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub getoptionsfromarray { |
137
|
1
|
|
|
1
|
|
13
|
my $obj = shift; |
138
|
1
|
|
|
|
|
2
|
my $argv = $_[0]; |
139
|
1
|
|
|
|
|
2
|
my $loader = $obj->{exloader}; |
140
|
|
|
|
|
|
|
|
141
|
1
|
|
|
|
|
5
|
$loader->deal_with($argv); |
142
|
|
|
|
|
|
|
|
143
|
1
|
|
|
|
|
3
|
my @builtins = do { |
144
|
1
|
50
|
|
|
|
4
|
if (ref $_[1] eq 'HASH') { |
145
|
1
|
|
|
|
|
4
|
$loader->hashed_builtins($_[1]); |
146
|
|
|
|
|
|
|
} else { |
147
|
0
|
|
|
|
|
0
|
$loader->builtins; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
}; |
150
|
1
|
|
|
|
|
6
|
push @_, @builtins; |
151
|
|
|
|
|
|
|
|
152
|
1
|
|
|
|
|
17
|
$obj->SUPER::getoptionsfromarray(@_); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 NAME |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Getopt::EX::Long - Getopt::Long compatible glue module |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SYNOPSIS |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
use Getopt::EX::Long; |
164
|
|
|
|
|
|
|
GetOptions(...); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
or |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
require Getopt::EX::Long; |
169
|
|
|
|
|
|
|
my $parser = Getopt::EX::Long::Parser->new( |
170
|
|
|
|
|
|
|
config => [ Getopt::Long option ... ], |
171
|
|
|
|
|
|
|
exconfig => [ Getopt::EX::Long option ...], |
172
|
|
|
|
|
|
|
); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 DESCRIPTION |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L is almost compatible to L and you |
177
|
|
|
|
|
|
|
can just replace module declaration and it should work just same as |
178
|
|
|
|
|
|
|
before (See L section). |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Besides working same, user can define their own option aliases and |
181
|
|
|
|
|
|
|
write dynamically loaded extension module. If the command name is |
182
|
|
|
|
|
|
|
I, |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
~/.examplerc |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
file is loaded by default. In this rc file, user can define their own |
187
|
|
|
|
|
|
|
option with macro processing. This is useful when the command takes |
188
|
|
|
|
|
|
|
complicated arguments. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Also, special command option preceded by B<-M> is taken and |
191
|
|
|
|
|
|
|
corresponding perl module is loaded. Module is assumed under the |
192
|
|
|
|
|
|
|
specific base class. For example, |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
% example -Mfoo |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
will load C module, by default. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This module is normal perl module, so user can write any kind of |
199
|
|
|
|
|
|
|
program. If the module is specified with initial function call, it is |
200
|
|
|
|
|
|
|
called at the beginning of command execution. Suppose that the |
201
|
|
|
|
|
|
|
module I is specified like this: |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
% example -Mfoo::bar(buz=100) ... |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Then, after the module B is loaded, function I is called |
206
|
|
|
|
|
|
|
with the parameter I which has value 100. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
If the module includes C<__DATA__> section, it is interpreted just |
209
|
|
|
|
|
|
|
same as rc file. So you can define arbitrary option there. Combined |
210
|
|
|
|
|
|
|
with startup function call described above, it is possible to control |
211
|
|
|
|
|
|
|
module behavior by user defined option. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
As for start-up file and Module specification, read |
214
|
|
|
|
|
|
|
L document for detail. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 CONFIG OPTIONS |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Config options are set by B or B |
219
|
|
|
|
|
|
|
parameter for B method. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=over 4 |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item AUTO_DEFAULT |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Config option B and B are automatically set based |
226
|
|
|
|
|
|
|
on the name of command executable. If you don't want this behavior, |
227
|
|
|
|
|
|
|
set B to 0. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=back |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Other options including B and B are passed to |
232
|
|
|
|
|
|
|
B. Read its document for detail. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 INCOMPATIBILITY |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Subroutine B is not supported. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 SEE ALSO |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
L, |
241
|
|
|
|
|
|
|
L, |
242
|
|
|
|
|
|
|
L |