line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::EX::LabeledParam; |
2
|
10
|
|
|
10
|
|
4761
|
use version; our $VERSION = version->declare("2.1.2"); |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
50
|
|
3
|
|
|
|
|
|
|
|
4
|
10
|
|
|
10
|
|
949
|
use v5.14; |
|
10
|
|
|
|
|
36
|
|
5
|
10
|
|
|
10
|
|
82
|
use warnings; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
364
|
|
6
|
10
|
|
|
10
|
|
60
|
use Carp; |
|
10
|
|
|
|
|
35
|
|
|
10
|
|
|
|
|
775
|
|
7
|
|
|
|
|
|
|
|
8
|
10
|
|
|
10
|
|
80
|
use Exporter 'import'; |
|
10
|
|
|
|
|
28
|
|
|
10
|
|
|
|
|
865
|
|
9
|
|
|
|
|
|
|
our @EXPORT = qw(); |
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(); |
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); |
12
|
|
|
|
|
|
|
|
13
|
10
|
|
|
10
|
|
68
|
use Data::Dumper; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
487
|
|
14
|
10
|
|
|
10
|
|
2483
|
use Getopt::EX::Module; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
457
|
|
15
|
10
|
|
|
10
|
|
76
|
use Getopt::EX::Func qw(parse_func); |
|
10
|
|
|
|
|
24
|
|
|
10
|
|
|
|
|
12020
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
2
|
|
|
2
|
1
|
5
|
my $class = shift; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
14
|
my $obj = bless { |
21
|
|
|
|
|
|
|
NEWLABEL => 0, |
22
|
|
|
|
|
|
|
CONCAT => "", |
23
|
|
|
|
|
|
|
HASH => {}, |
24
|
|
|
|
|
|
|
LIST => [], |
25
|
|
|
|
|
|
|
}, $class; |
26
|
|
|
|
|
|
|
|
27
|
2
|
50
|
|
|
|
9
|
$obj->configure(@_) if @_; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
5
|
$obj; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub configure { |
33
|
2
|
|
|
2
|
1
|
6
|
my $obj = shift; |
34
|
2
|
|
|
|
|
8
|
while (@_ >= 2) { |
35
|
4
|
|
|
|
|
13
|
my($k, $v) = splice @_, 0, 2; |
36
|
4
|
50
|
33
|
|
|
28
|
if ($k =~ /^\w/ and exists $obj->{$k}) { |
37
|
4
|
|
|
|
|
15
|
$obj->{$k} = $v; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
2
|
|
|
|
|
5
|
$obj; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
1
|
0
|
18
|
sub get_hash { shift->{HASH} } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub set_hash { |
46
|
0
|
|
|
0
|
0
|
0
|
my $obj = shift; |
47
|
0
|
|
|
|
|
0
|
%{ $obj->{HASH} } = @_; |
|
0
|
|
|
|
|
0
|
|
48
|
0
|
|
|
|
|
0
|
$obj; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
0
|
0
|
0
|
sub list { @{ shift->{LIST} } } |
|
0
|
|
|
|
|
0
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub push_list { |
54
|
0
|
|
|
0
|
0
|
0
|
my $obj = shift; |
55
|
0
|
|
|
|
|
0
|
push @{ $obj->{LIST} }, @_; |
|
0
|
|
|
|
|
0
|
|
56
|
0
|
|
|
|
|
0
|
$obj; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub set_list { |
60
|
0
|
|
|
0
|
0
|
0
|
my $obj = shift; |
61
|
0
|
|
|
|
|
0
|
@{ $obj->{LIST} } = @_; |
|
0
|
|
|
|
|
0
|
|
62
|
0
|
|
|
|
|
0
|
$obj; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub append { |
66
|
0
|
|
|
0
|
1
|
0
|
my $obj = shift; |
67
|
0
|
|
|
|
|
0
|
for my $item (@_) { |
68
|
0
|
0
|
|
|
|
0
|
if (ref $item eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
push @{$obj->{LIST}}, @$item; |
|
0
|
|
|
|
|
0
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
elsif (ref $item eq 'HASH') { |
72
|
0
|
|
|
|
|
0
|
while (my($k, $v) = each %$item) { |
73
|
0
|
|
|
|
|
0
|
$obj->{HASH}->{$k} = $v; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else { |
77
|
0
|
|
|
|
|
0
|
push @{$obj->{LIST}}, $item; |
|
0
|
|
|
|
|
0
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub load_params { |
83
|
6
|
|
|
6
|
1
|
4025
|
my $obj = shift; |
84
|
|
|
|
|
|
|
|
85
|
6
|
|
|
|
|
24
|
my $re_field = qr/[\w\*\?]+/; |
86
|
|
|
|
|
|
|
map { |
87
|
11
|
|
|
|
|
24
|
my $spec = pop @$_; |
88
|
11
|
|
|
|
|
17
|
my @spec; |
89
|
11
|
|
|
|
|
51
|
while ($spec =~ s/\&([:\w]+ (?: \( [^)]* \) )? ) ;?//x) { # &func |
90
|
5
|
|
|
|
|
26
|
push @spec, parse_func({ PACKAGE => 'main' }, $1); |
91
|
|
|
|
|
|
|
} |
92
|
11
|
100
|
|
|
|
35
|
if ($spec =~ s/\b(sub\s*{.*)//) { # sub { ... } |
93
|
2
|
|
|
|
|
11
|
push @spec, parse_func({ PACKAGE => 'main' }, $1); |
94
|
|
|
|
|
|
|
} |
95
|
11
|
100
|
|
|
|
31
|
push @spec, $spec if $spec ne ''; |
96
|
11
|
50
|
|
|
|
34
|
my $c = @spec > 1 ? [ @spec ] : @spec == 1 ? $spec[0] : ""; |
|
|
100
|
|
|
|
|
|
97
|
11
|
50
|
|
|
|
27
|
if (@$_ == 0) { |
98
|
0
|
|
|
|
|
0
|
$obj->push_list($c); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
|
|
|
|
|
|
map { |
102
|
22
|
100
|
|
|
|
73
|
if ($c =~ /^\++(.*)/) { # LABEL=+ATTR |
|
|
100
|
|
|
|
|
|
103
|
9
|
|
|
|
|
29
|
$obj->{HASH}->{$_} .= $obj->{CONCAT} . "$1"; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
elsif ($c =~ /^\-+(.*)$/i) { # LABEL=-ATTR |
106
|
2
|
|
|
|
|
6
|
my $chars = $1 =~ s/(?=\W)/\\/gr; |
107
|
2
|
|
|
|
|
21
|
$obj->{HASH}->{$_} =~ s/[$chars]+//g; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
11
|
|
|
|
|
53
|
$obj->{HASH}->{$_} = $c; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
map { |
114
|
|
|
|
|
|
|
# plain label |
115
|
11
|
100
|
|
|
|
20
|
if (not /\W/) { |
|
11
|
|
|
|
|
35
|
|
116
|
5
|
50
|
|
|
|
15
|
if (exists $obj->{HASH}->{$_}) { |
117
|
5
|
|
|
|
|
13
|
$_; |
118
|
|
|
|
|
|
|
} else { |
119
|
0
|
0
|
|
|
|
0
|
if ($obj->{NEWLABEL}) { |
120
|
0
|
|
|
|
|
0
|
$_; |
121
|
|
|
|
|
|
|
} else { |
122
|
0
|
|
|
|
|
0
|
warn "$_: Unknown label\n"; |
123
|
0
|
|
|
|
|
0
|
(); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
# wild card |
128
|
|
|
|
|
|
|
else { |
129
|
6
|
|
|
|
|
9
|
my @labels = match_glob($_, keys %{$obj->{HASH}}); |
|
6
|
|
|
|
|
22
|
|
130
|
6
|
50
|
|
|
|
15
|
if (@labels == 0) { |
131
|
0
|
|
|
|
|
0
|
warn "$_: Unmatched label\n"; |
132
|
|
|
|
|
|
|
} |
133
|
6
|
|
|
|
|
20
|
@labels; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
@$_; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
map { |
140
|
11
|
50
|
|
|
|
179
|
if (my @field = /\G($re_field)=/gp) { |
141
|
11
|
|
|
|
|
55
|
[ @field, ${^POSTMATCH} ]; |
142
|
|
|
|
|
|
|
} else { |
143
|
0
|
|
|
|
|
0
|
[ $_ ]; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
map { |
147
|
6
|
|
|
|
|
16
|
m/( (?: $re_field= )* |
|
11
|
|
|
|
|
410
|
|
148
|
|
|
|
|
|
|
(?: .* \b sub \s* \{ .* |
149
|
|
|
|
|
|
|
| (?: \([^)]*\) | [^,\s] )+ |
150
|
|
|
|
|
|
|
) |
151
|
|
|
|
|
|
|
)/gx; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
@_; |
154
|
|
|
|
|
|
|
|
155
|
6
|
|
|
|
|
24
|
$obj; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub match_glob { |
159
|
6
|
|
|
6
|
0
|
9
|
local $_ = shift; |
160
|
6
|
|
|
|
|
12
|
s/\?/./g; |
161
|
6
|
|
|
|
|
15
|
s/\*/.*/g; |
162
|
6
|
|
|
|
|
68
|
my $regex = qr/^$_$/; |
163
|
6
|
|
|
|
|
13
|
grep { $_ =~ $regex } @_; |
|
36
|
|
|
|
|
126
|
|
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 NAME |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Getopt::EX::LabeledParam - Labeled parameter handling |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SYNOPSIS |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
GetOptions('colormap|cm:s' => @opt_colormap); |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# default values |
178
|
|
|
|
|
|
|
my %colormap = ( FILE => 'DR', LINE => 'Y', TEXT => '' ); |
179
|
|
|
|
|
|
|
my @colors = qw( /544 /545 /445 /455 /545 /554 ); |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
require Getopt::EX::LabeledParam; |
182
|
|
|
|
|
|
|
my $cmap = Getopt::EX::LabeledParam |
183
|
|
|
|
|
|
|
->new( NEWLABEL => 0, |
184
|
|
|
|
|
|
|
HASH => \%colormap, |
185
|
|
|
|
|
|
|
LIST => \@colors ) |
186
|
|
|
|
|
|
|
->load_params(@opt_colormap); |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 DESCRIPTION |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This module implements super class of L. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Parameters can be given in two ways: one in labeled table, and one in |
194
|
|
|
|
|
|
|
indexed list. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Handler maintains hash and list objects, and labeled values are stored |
197
|
|
|
|
|
|
|
in hash, non-label values are in list automatically. User can mix |
198
|
|
|
|
|
|
|
both specifications. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
When the value field has a special form of function call, |
201
|
|
|
|
|
|
|
L object is created and stored for that entry. See |
202
|
|
|
|
|
|
|
L section in L for more detail. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 HASH |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Basically, labeled parameter is defined by B |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
FILE=R |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Definition can be connected by comma (C<,>): |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
FILE=R,LINE=G |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Multiple labels can be set for same value: |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
FILE=LINE=TEXT=R |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Wildcard C<*> and C> can be used in label name, and they matches |
219
|
|
|
|
|
|
|
existing hash key name. If labels C and C exists |
220
|
|
|
|
|
|
|
in hash, |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
*FILE=R |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
and |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
OLD_FILE=NEW_FILE=R |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
produces same result. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
If B part start with plus (C<+>) character, it is appended to |
231
|
|
|
|
|
|
|
current value. At this time, C string is inserted before |
232
|
|
|
|
|
|
|
additional string. Default C strings is empty, so use |
233
|
|
|
|
|
|
|
configure method to set. If B part start with minus (C<->) |
234
|
|
|
|
|
|
|
character, following characters are deleted from the current value. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 LIST |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
If B |
239
|
|
|
|
|
|
|
stored in list object. For example, |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
R,G,B,C,M,Y |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
makes six entries in the list. The list object is accessed by index, |
244
|
|
|
|
|
|
|
rather than label. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 METHODS |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=over 4 |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item B |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=item B |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=over 4 |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=item B =E I |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=item B =E I |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
B and B reference can be set by B or B |
261
|
|
|
|
|
|
|
method. You can provide default setting of hash and list, and it is |
262
|
|
|
|
|
|
|
usually easier to access those values directly, rather than through |
263
|
|
|
|
|
|
|
class methods. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item B =E 0/1 |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
By default, B does not create new entry in hash table, |
268
|
|
|
|
|
|
|
and absent label is ignored. Setting parameter true makes |
269
|
|
|
|
|
|
|
it possible create a new hash entry. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=item B =E I |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Set concatenation string inserted before appending string. |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=back |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=item B I |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
Load option list into the object. |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item B HASHREF or LIST |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
Provide simple interface to append colormap hash or color list. If a |
284
|
|
|
|
|
|
|
hash reference is given, all entry of the hash is appended to the |
285
|
|
|
|
|
|
|
colormap. Otherwise, they are appended anonymous color list. |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=back |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=head1 SEE ALSO |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
L |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
# LocalWords: CONCAT hashref listref NEWLABEL HASHREF colormap |