File Coverage

blib/lib/App/BatParser.pm
Criterion Covered Total %
statement 19 21 90.4
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 27 31 87.1


line stmt bran cond sub pod time code
1             package App::BatParser;
2              
3 8     8   476462 use utf8;
  8         78  
  8         42  
4              
5 8     8   7902 use Regexp::Grammars;
  8         158740  
  8         67  
6 8     8   5212 use Moo;
  8         77045  
  8         42  
7 8     8   13530 use namespace::autoclean;
  8         92989  
  8         47  
8              
9             our $VERSION = '0.009'; # VERSION
10              
11             # ABSTRACT: Parse DOS .bat and .cmd files
12              
13             has 'grammar' => (
14             is => 'ro',
15             default => sub {
16             return qr{
17            
18            
19            
20             (?:<[Lines]>\n)*
21              
22             |
23              
24             \:\: | REM
25              
26             \:(?!:)[^\n]*
27              
28             \@?
29            
30             (?: || )
31              
32             | | | | |
33              
34             echo (?: | )
35              
36             off
37              
38             If (?: | )
39              
40             |
41              
42             NOT
43              
44             EXIST
45              
46            
47              
48             call
49              
50             Goto :?
51              
52             set =
53              
54             for DO
55              
56             NEQ | EQU | GTR | == | LSS | LEQ | GEQ
57              
58             [^:\n\s]+
59              
60             [^\s]+
61              
62             [^\n]*
63              
64             [^\n\s\:]*
65              
66             }xmi;
67             }
68             );
69              
70             sub parse {
71 7     7 1 42 my $self = shift;
72 7         15 my $text = shift;
73              
74 7 50       29 if ( $^O eq 'MSWin32' ) {
75              
76             # First join lines splited in multiple lines
77 0         0 $text =~ s/\^\n//msg;
78             }
79             else {
80             # First join lines splited in multiple lines
81 7         26 $text =~ s/\^\r\n//msg;
82 7         48 $text =~ s/\r\n/\n/msg;
83             }
84              
85 7 50       223 if ( $text =~ $self->grammar ) {
86 7         47 return \%/;
87             }
88             else {
89 0           return ();
90             }
91             }
92              
93             __PACKAGE__->meta->make_immutable;
94              
95             1;
96              
97             __END__