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