line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package YATT::Util::CmdLine; |
2
|
3
|
|
|
3
|
|
809
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
87
|
|
3
|
3
|
|
|
3
|
|
16
|
use warnings qw(FATAL all NONFATAL misc); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
182
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
14
|
BEGIN {require Exporter; *import = \&Exporter::import} |
|
3
|
|
|
|
|
1276
|
|
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
|
1397
|
my ($pack, $list, $result) = @_; |
13
|
4
|
|
|
|
|
6
|
my $wantarray = wantarray; |
14
|
4
|
100
|
|
|
|
13
|
unless (defined $result) { |
15
|
2
|
100
|
|
|
|
6
|
$result = $wantarray ? [] : {}; |
16
|
|
|
|
|
|
|
} |
17
|
4
|
|
100
|
|
|
44
|
while (@$list |
18
|
|
|
|
|
|
|
and my ($n, $v) = $list->[0] =~ /^--(?:([\w\.\-]+)(?:=(.*))?)?/) { |
19
|
10
|
|
|
|
|
14
|
shift @$list; |
20
|
10
|
100
|
|
|
|
25
|
last unless defined $n; |
21
|
8
|
100
|
|
|
|
17
|
$v = 1 unless defined $v; |
22
|
8
|
100
|
|
|
|
17
|
if (ref $result eq 'HASH') { |
23
|
2
|
|
|
|
|
19
|
$result->{$n} = $v; |
24
|
|
|
|
|
|
|
} else { |
25
|
6
|
|
|
|
|
47
|
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
|
542
|
my ($pack, $list, $hash) = @_; |
34
|
3
|
|
|
|
|
5
|
my $explicit; |
35
|
3
|
100
|
|
|
|
9
|
unless (defined $hash) { |
36
|
2
|
|
|
|
|
5
|
$hash = {} |
37
|
|
|
|
|
|
|
} else { |
38
|
1
|
|
|
|
|
2
|
$explicit++; |
39
|
|
|
|
|
|
|
} |
40
|
3
|
|
66
|
|
|
26
|
for (; @$list and $list->[0] =~ /^([^=]+)=(.*)/; shift @$list) { |
41
|
2
|
|
|
|
|
21
|
$hash->{$1} = $2; |
42
|
|
|
|
|
|
|
} |
43
|
3
|
100
|
100
|
|
|
15
|
if (not $explicit and wantarray) { |
44
|
|
|
|
|
|
|
# return empty list if hash is empty |
45
|
1
|
50
|
|
|
|
7
|
%$hash ? $hash : (); |
46
|
|
|
|
|
|
|
} else { |
47
|
2
|
|
|
|
|
12
|
$hash |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |