line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::EX::Long; |
2
|
4
|
|
|
4
|
|
241945
|
use version; our $VERSION = version->declare("2.1.2"); |
|
4
|
|
|
|
|
6168
|
|
|
4
|
|
|
|
|
26
|
|
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
413
|
use v5.14; |
|
4
|
|
|
|
|
22
|
|
5
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
118
|
|
6
|
4
|
|
|
4
|
|
26
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
535
|
|
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
|
|
28
|
use Exporter 'import'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
352
|
|
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
|
|
27
|
use Data::Dumper; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
254
|
|
28
|
4
|
|
|
4
|
|
3181
|
use Getopt::Long(); |
|
4
|
|
|
|
|
51185
|
|
|
4
|
|
|
|
|
152
|
|
29
|
4
|
|
|
4
|
|
1508
|
use Getopt::EX::Loader; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
196
|
|
30
|
4
|
|
|
4
|
|
31
|
use Getopt::EX::Func qw(parse_func); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1237
|
|
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
|
10416
|
unshift @_, \@ARGV; |
39
|
2
|
|
|
|
|
12
|
goto &GetOptionsFromArray; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub GetOptionsFromArray { |
43
|
2
|
|
|
2
|
0
|
6
|
my $argv = $_[0]; |
44
|
|
|
|
|
|
|
|
45
|
2
|
50
|
|
|
|
20
|
set_default() if $ConfigOption{AUTO_DEFAULT}; |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
33
|
|
|
16
|
$loader //= Getopt::EX::Loader->new(do { |
48
|
|
|
|
|
|
|
map { |
49
|
2
|
100
|
|
|
|
8
|
exists $ConfigOption{$_} ? ( $_ => $ConfigOption{$_} ) : () |
|
12
|
|
|
|
|
50
|
|
50
|
|
|
|
|
|
|
} @Getopt::EX::Loader::OPTIONS |
51
|
|
|
|
|
|
|
}); |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
11
|
$loader->deal_with($argv); |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
4
|
my @builtins = do { |
56
|
2
|
100
|
|
|
|
9
|
if (ref $_[1] eq 'HASH') { |
57
|
1
|
|
|
|
|
6
|
$loader->hashed_builtins($_[1]); |
58
|
|
|
|
|
|
|
} else { |
59
|
1
|
|
|
|
|
13
|
$loader->builtins; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
}; |
62
|
2
|
|
|
|
|
16
|
push @_, @builtins; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
13
|
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
|
|
31
|
use List::Util qw(pairmap); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
995
|
|
83
|
3
|
|
33
|
3
|
0
|
28
|
pairmap { $ConfigOption{$a} //= $b } get_default(); |
|
2
|
|
|
2
|
|
15
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get_default { |
87
|
3
|
|
|
3
|
0
|
7
|
my @list; |
88
|
|
|
|
|
|
|
|
89
|
3
|
50
|
|
|
|
35
|
my $prog = ($0 =~ /([^\/]+)$/) ? $1 : return (); |
90
|
|
|
|
|
|
|
|
91
|
3
|
50
|
|
|
|
19
|
if (defined (my $home = $ENV{HOME})) { |
92
|
3
|
100
|
|
|
|
90
|
if (-f (my $rc = "$home/.${prog}rc")) { |
93
|
1
|
|
|
|
|
6
|
push @list, RCFILE => $rc; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
15
|
push @list, BASECLASS => "App::$prog"; |
98
|
|
|
|
|
|
|
|
99
|
3
|
|
|
|
|
38
|
@list; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
############################################################ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
package Getopt::EX::Long::Parser; |
107
|
|
|
|
|
|
|
|
108
|
4
|
|
|
4
|
|
40
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
148
|
|
109
|
4
|
|
|
4
|
|
28
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
184
|
|
110
|
|
|
|
|
|
|
|
111
|
4
|
|
|
4
|
|
28
|
use List::Util qw(first); |
|
4
|
|
|
|
|
19
|
|
|
4
|
|
|
|
|
224
|
|
112
|
4
|
|
|
4
|
|
30
|
use Data::Dumper; |
|
4
|
|
|
|
|
25
|
|
|
4
|
|
|
|
|
223
|
|
113
|
|
|
|
|
|
|
|
114
|
4
|
|
|
4
|
|
25
|
use Getopt::EX::Loader; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1521
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
our @ISA = qw(Getopt::Long::Parser); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub new { |
119
|
1
|
|
|
1
|
|
207
|
my $class = shift; |
120
|
|
|
|
|
|
|
|
121
|
1
|
|
|
|
|
2
|
my @exconfig; |
122
|
1
|
|
|
0
|
|
16
|
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
|
|
|
12
|
if (@exconfig == 0 and $ConfigOption{AUTO_DEFAULT}) { |
126
|
1
|
|
|
|
|
3
|
@exconfig = Getopt::EX::Long::get_default(); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
12
|
my $obj = $class->SUPER::new(@_); |
130
|
|
|
|
|
|
|
|
131
|
1
|
|
|
|
|
32
|
my $loader = $obj->{exloader} = Getopt::EX::Loader->new(@exconfig); |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
|
|
4
|
$obj; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub getoptionsfromarray { |
137
|
1
|
|
|
1
|
|
14
|
my $obj = shift; |
138
|
1
|
|
|
|
|
3
|
my $argv = $_[0]; |
139
|
1
|
|
|
|
|
3
|
my $loader = $obj->{exloader}; |
140
|
|
|
|
|
|
|
|
141
|
1
|
|
|
|
|
5
|
$loader->deal_with($argv); |
142
|
|
|
|
|
|
|
|
143
|
1
|
|
|
|
|
2
|
my @builtins = do { |
144
|
1
|
50
|
|
|
|
5
|
if (ref $_[1] eq 'HASH') { |
145
|
1
|
|
|
|
|
4
|
$loader->hashed_builtins($_[1]); |
146
|
|
|
|
|
|
|
} else { |
147
|
0
|
|
|
|
|
0
|
$loader->builtins; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
}; |
150
|
1
|
|
|
|
|
4
|
push @_, @builtins; |
151
|
|
|
|
|
|
|
|
152
|
1
|
|
|
|
|
18
|
$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 |