line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::CommandLine::Regexp; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2020-04-09'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'Parse-CommandLine-Regexp'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
68910
|
use strict; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
30
|
|
9
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
6
|
use Exporter qw(import); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
431
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(parse_command_line); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _remove_backslash { |
15
|
36
|
|
|
36
|
|
70
|
my $s = shift; |
16
|
36
|
|
|
|
|
86
|
$s =~ s/\\(.)/$1/g; |
17
|
36
|
|
|
|
|
85
|
$s; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub parse_command_line { |
21
|
17
|
|
|
17
|
1
|
2407
|
my $line = shift; |
22
|
|
|
|
|
|
|
|
23
|
17
|
|
|
|
|
31
|
my @words; |
24
|
|
|
|
|
|
|
my $after_ws; |
25
|
17
|
|
|
|
|
131
|
$line =~ s!( # 1) everything |
26
|
|
|
|
|
|
|
(")((?: \\\\|\\"|[^"])*)(?:"|\z)(\s*) | # 2) open " 3) content 4) space after |
27
|
|
|
|
|
|
|
(')((?: \\\\|\\'|[^'])*)(?:'|\z)(\s*) | # 5) open ' 6) content 7) space after |
28
|
|
|
|
|
|
|
((?: \\\\|\\"|\\'|\\\s|[^"'\s])+)(\s*) | # 8) unquoted word 9) space after |
29
|
|
|
|
|
|
|
\s+ |
30
|
|
|
|
|
|
|
)! |
31
|
36
|
100
|
|
|
|
176
|
if ($2) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
32
|
6
|
50
|
|
|
|
15
|
if ($after_ws) { |
33
|
6
|
|
|
|
|
15
|
push @words, _remove_backslash($3); |
34
|
|
|
|
|
|
|
} else { |
35
|
0
|
0
|
|
|
|
0
|
push @words, '' unless @words; |
36
|
0
|
|
|
|
|
0
|
$words[$#words] .= _remove_backslash($3); |
37
|
|
|
|
|
|
|
} |
38
|
6
|
|
|
|
|
29
|
$after_ws = $4; |
39
|
|
|
|
|
|
|
} elsif ($5) { |
40
|
5
|
50
|
|
|
|
11
|
if ($after_ws) { |
41
|
5
|
|
|
|
|
12
|
push @words, _remove_backslash($6); |
42
|
|
|
|
|
|
|
} else { |
43
|
0
|
0
|
|
|
|
0
|
push @words, '' unless @words; |
44
|
0
|
|
|
|
|
0
|
$words[$#words] .= _remove_backslash($6); |
45
|
|
|
|
|
|
|
} |
46
|
5
|
|
|
|
|
16
|
$after_ws = $7; |
47
|
|
|
|
|
|
|
} elsif (defined $8) { |
48
|
25
|
100
|
|
|
|
48
|
if ($after_ws) { |
49
|
9
|
|
|
|
|
18
|
push @words, _remove_backslash($8); |
50
|
|
|
|
|
|
|
} else { |
51
|
16
|
50
|
|
|
|
45
|
push @words, '' unless @words; |
52
|
16
|
|
|
|
|
43
|
$words[$#words] .= _remove_backslash($8); |
53
|
|
|
|
|
|
|
} |
54
|
25
|
|
|
|
|
168
|
$after_ws = $9; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
!egx; |
57
|
|
|
|
|
|
|
|
58
|
17
|
|
|
|
|
153
|
@words; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
# ABSTRACT: Parsing string like command line |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |