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 9     9   463381 use utf8;
  9         79  
  9         42  
4              
5 9     9   8248 use Regexp::Grammars;
  9         157058  
  9         48  
6 9     9   5061 use Moo;
  9         72788  
  9         33  
7 9     9   12365 use namespace::autoclean;
  9         85385  
  9         30  
8              
9             our $VERSION = '0.010'; # 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]>)*
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 8     8 1 38 my $self = shift;
72 8         17 my $text = shift;
73              
74 8 50       28 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 8         25 $text =~ s/\^\r\n//msg;
82 8         45 $text =~ s/\r\n/\n/msg;
83             }
84              
85 8 50       210 if ( $text =~ $self->grammar ) {
86 8         42 return \%/;
87             }
88             else {
89 0           return ();
90             }
91             }
92              
93             __PACKAGE__->meta->make_immutable;
94              
95             1;
96              
97             __END__