line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package YATT::Util::CmdLine; |
2
|
3
|
|
|
3
|
|
753
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
92
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings qw(FATAL all NONFATAL misc); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
186
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
14
|
BEGIN {require Exporter; *import = \&Exporter::import} |
|
3
|
|
|
|
|
1292
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw(parse_opts parse_params); |
8
|
|
|
|
|
|
|
our @EXPORT = @EXPORT_OK; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# posix style option. |
11
|
|
|
|
|
|
|
sub parse_opts { |
12
|
4
|
|
|
4
|
0
|
1325
|
my ($pack, $list, $result) = @_; |
13
|
4
|
|
|
|
|
7
|
my $wantarray = wantarray; |
14
|
4
|
100
|
|
|
|
12
|
unless (defined $result) { |
15
|
2
|
100
|
|
|
|
6
|
$result = $wantarray ? [] : {}; |
16
|
|
|
|
|
|
|
} |
17
|
4
|
|
100
|
|
|
38
|
while (@$list |
18
|
|
|
|
|
|
|
and my ($n, $v) = $list->[0] =~ /^--(?:([\w\.\-]+)(?:=(.*))?)?/) { |
19
|
10
|
|
|
|
|
15
|
shift @$list; |
20
|
10
|
100
|
|
|
|
44
|
last unless defined $n; |
21
|
8
|
100
|
|
|
|
18
|
$v = 1 unless defined $v; |
22
|
8
|
100
|
|
|
|
20
|
if (ref $result eq 'HASH') { |
23
|
2
|
|
|
|
|
20
|
$result->{$n} = $v; |
24
|
|
|
|
|
|
|
} else { |
25
|
6
|
|
|
|
|
44
|
push @$result, $n, $v; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
4
|
100
|
66
|
|
|
40
|
$wantarray && ref $result ne 'HASH' ? @$result : $result; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# 'Make' style parameter. |
32
|
|
|
|
|
|
|
sub parse_params { |
33
|
3
|
|
|
3
|
0
|
545
|
my ($pack, $list, $hash) = @_; |
34
|
3
|
|
|
|
|
5
|
my $explicit; |
35
|
3
|
100
|
|
|
|
7
|
unless (defined $hash) { |
36
|
2
|
|
|
|
|
5
|
$hash = {} |
37
|
|
|
|
|
|
|
} else { |
38
|
1
|
|
|
|
|
2
|
$explicit++; |
39
|
|
|
|
|
|
|
} |
40
|
3
|
|
66
|
|
|
22
|
for (; @$list and $list->[0] =~ /^([^=]+)=(.*)/; shift @$list) { |
41
|
2
|
|
|
|
|
16
|
$hash->{$1} = $2; |
42
|
|
|
|
|
|
|
} |
43
|
3
|
100
|
100
|
|
|
13
|
if (not $explicit and wantarray) { |
44
|
|
|
|
|
|
|
# return empty list if hash is empty |
45
|
1
|
50
|
|
|
|
7
|
%$hash ? $hash : (); |
46
|
|
|
|
|
|
|
} else { |
47
|
2
|
|
|
|
|
10
|
$hash |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |