File Coverage

blib/lib/Parse/CommandLine/Regexp.pm
Criterion Covered Total %
statement 28 32 87.5
branch 10 18 55.5
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 44 56 78.5


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