File tree Expand file tree Collapse file tree 2 files changed +66
-2
lines changed Expand file tree Collapse file tree 2 files changed +66
-2
lines changed Original file line number Diff line number Diff line change 9
9
package XML::Axk::Preparse ;
10
10
use XML::Axk::Base qw( :all) ;
11
11
12
+ use Devel::Peek;
13
+
12
14
=encoding UTF-8
13
15
14
16
=head1 NAME
@@ -95,8 +97,11 @@ sub pieces {
95
97
next ;
96
98
}
97
99
98
- # Otherwise, normal line
99
- die " Source text can't come before a pragma line" unless @retval ;
100
+ # Otherwise, normal line.
101
+ unless (/ ^\h *(#|$) / ) { # Ignore blanks and comments before the
102
+ # first Ln.
103
+ die " Source text can't come before a pragma line" unless @retval ;
104
+ }
100
105
$retval [-1]-> {text } .= $_ ;
101
106
}
102
107
close $fh ;
@@ -161,6 +166,25 @@ sub assemble {
161
166
return \$retval ;
162
167
} # assemble()
163
168
169
+ =head2 preparse
170
+
171
+ Invokes pieces() and assemble(). Usage:
172
+
173
+ my $srTextOut = preparse($filename, $textIn);
174
+
175
+ C<textIn > can be a string or a string ref.
176
+
177
+ =cut
178
+
179
+ sub preparse {
180
+ my $filename = $_ [0] or croak(' Need filename' );
181
+ my $srTextIn = $_ [1] or croak(' Need text' );
182
+ $srTextIn = \$_ [1] unless ref $srTextIn eq ' SCALAR' ;
183
+
184
+ my $hrPieces = pieces($srTextIn );
185
+ my $srTextOut = assemble($filename , $hrPieces );
186
+ return $srTextOut ;
187
+ } # preparse()
164
188
165
189
1;
166
190
# vi: set ts=4 sts=4 sw=4 et ai fo-=ro foldmethod=marker: #
Original file line number Diff line number Diff line change
1
+ # !perl
2
+ # 01-preparse.t
3
+
4
+ use 5.018;
5
+ use strict;
6
+ use warnings;
7
+ use Test::More;
8
+ use Capture::Tiny ' capture_stdout' ;
9
+ use File::Spec;
10
+
11
+ BEGIN {
12
+ use_ok( ' XML::Axk::Preparse' ) || print " Bail out!\n " ;
13
+ }
14
+
15
+ # sub localpath {
16
+ # state $voldir = [File::Spec->splitpath(__FILE__)];
17
+ # return File::Spec->catpath($voldir->[0], $voldir->[1], shift)
18
+ # }
19
+
20
+ # Convenient alias
21
+ local *pp = sub { goto &XML::Axk::Preparse::preparse; };
22
+
23
+ my $srTest ;
24
+
25
+ $srTest = pp(' foo' , <<'EOT' );
26
+ #!x -L1
27
+ EOT
28
+ like($$srTest , qr / ^use XML::Axk::L::L1/ );
29
+ like($$srTest , qr / ^#line.*foo/ m );
30
+
31
+ $srTest = pp(' foo' , <<'EOT' );
32
+ -L1
33
+ EOT
34
+ like($$srTest , qr / ^use XML::Axk::L::L1/ );
35
+ like($$srTest , qr / ^#line.*foo/ m );
36
+
37
+
38
+ done_testing();
39
+
40
+ # vi: set ts=4 sts=4 sw=4 et ai fdm=marker fdl=1: #
You can’t perform that action at this time.
0 commit comments