line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Shebangml::State; |
2
|
|
|
|
|
|
|
$VERSION = v0.0.1; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
937
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Shebangml::State - input/parser state holder |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head2 new |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $state = Shebangml::State->new($source, %opts); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
0
|
|
|
0
|
1
|
|
my $package = shift; |
24
|
0
|
|
0
|
|
|
|
my $class = ref($package) || $package; |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
my $source = (@_ % 2) ? shift(@_) : undef; |
27
|
0
|
|
|
|
|
|
my %opts = @_; # TODO if I have opts, do I need to clone them? |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $self = {%opts}; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
defined($source) or croak("no source"); |
32
|
0
|
0
|
|
|
|
|
unless(ref($source)) { |
33
|
0
|
|
|
|
|
|
my $filename = $source; |
34
|
0
|
|
|
|
|
|
$source = undef; |
35
|
0
|
|
|
|
|
|
$self->{filename} = $filename; |
36
|
0
|
0
|
|
|
|
|
open($source, '<', $filename) or croak("cannot open '$filename' $!"); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
0
|
0
|
|
|
|
|
unless(defined(eval{fileno($source)})) { |
|
0
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $string = $$source; |
41
|
0
|
|
|
|
|
|
$source = undef; |
42
|
0
|
0
|
|
|
|
|
open($source, '<', \$string) or croak("cannot refopen string $!"); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$self->{in_fh} = $source; |
47
|
0
|
|
|
|
|
|
bless($self, $class); |
48
|
0
|
|
|
|
|
|
return($self); |
49
|
|
|
|
|
|
|
} # end subroutine new definition |
50
|
|
|
|
|
|
|
######################################################################## |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 next |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Reads another line into $state->current and returns a reference to it. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $CL = $state->next; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub next { |
61
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
defined(my $line = readline($self->{in_fh})) or return(); |
64
|
|
|
|
|
|
|
# return a reference to our inner buffer |
65
|
0
|
|
|
|
|
|
return($self->{current} = \($self->{line} = $line)); |
66
|
|
|
|
|
|
|
} # end subroutine next definition |
67
|
|
|
|
|
|
|
######################################################################## |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 current |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
A reference to the current line. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
0
|
1
|
|
sub current {shift(@_)->{current}} |
76
|
|
|
|
|
|
|
######################################################################## |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 Parser Bits |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 skip_comment |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$state->skip_comment; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub skip_comment { |
87
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $CL = $self->current; |
90
|
0
|
0
|
|
|
|
|
if($$CL =~ m/^\s*#{/) { |
91
|
0
|
|
|
|
|
|
while($CL = $self->next) { |
92
|
0
|
0
|
|
|
|
|
return if($$CL =~ m/^\s*#}/); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} # end subroutine skip_comment definition |
96
|
|
|
|
|
|
|
######################################################################## |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 skip_whitespace |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$state->skip_whitespace; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub skip_whitespace { |
105
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
while(my $CL = $self->next) { |
108
|
0
|
|
|
|
|
|
$$CL =~ s/^\s*//; |
109
|
0
|
0
|
|
|
|
|
return if(length($$CL)); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} # end subroutine skip_whitespace definition |
112
|
|
|
|
|
|
|
######################################################################## |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 read_literal |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $string = $state->read_literal($tag, $cr); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub read_literal { |
121
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
122
|
0
|
|
|
|
|
|
my ($tag, $cr) = @_; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my $out = ''; |
125
|
0
|
0
|
|
|
|
|
if($cr) { # end of that line |
126
|
0
|
|
|
|
|
|
$out .= "\n"; |
127
|
0
|
|
|
|
|
|
while(my $CL = $self->next) { |
128
|
0
|
0
|
|
|
|
|
if($$CL =~ s/^\s*\}\}\}(?:#([\.\w]+);)?//) { |
129
|
0
|
0
|
0
|
|
|
|
croak("$1 not $tag") if($1 and $1 ne $tag); |
130
|
0
|
|
|
|
|
|
return($out); |
131
|
|
|
|
|
|
|
} |
132
|
0
|
|
|
|
|
|
$out .= $$CL; |
133
|
|
|
|
|
|
|
} |
134
|
0
|
|
|
|
|
|
die "ASSERT: no fall-through case"; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
else { |
137
|
0
|
|
|
|
|
|
my $CL = $self->current; |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
$$CL =~ s/(.*?)}}}// or croak("no end on $tag"); |
140
|
0
|
|
|
|
|
|
$out .= $1; |
141
|
0
|
|
|
|
|
|
return($out); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
die "ASSERT: no fall-through case"; |
145
|
|
|
|
|
|
|
} # end subroutine read_literal definition |
146
|
|
|
|
|
|
|
######################################################################## |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 AUTHOR |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Eric Wilhelm @ |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
http://scratchcomputing.com/ |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 BUGS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
If you found this module on CPAN, please report any bugs or feature |
157
|
|
|
|
|
|
|
requests through the web interface at L. I will be |
158
|
|
|
|
|
|
|
notified, and then you'll automatically be notified of progress on your |
159
|
|
|
|
|
|
|
bug as I make changes. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
If you pulled this development version from my /svn/, please contact me |
162
|
|
|
|
|
|
|
directly. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 COPYRIGHT |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Copyright (C) 2008 Eric L. Wilhelm, All Rights Reserved. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 NO WARRANTY |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Absolutely, positively NO WARRANTY, neither express or implied, is |
171
|
|
|
|
|
|
|
offered with this software. You use this software at your own risk. In |
172
|
|
|
|
|
|
|
case of loss, no person or entity owes you anything whatsoever. You |
173
|
|
|
|
|
|
|
have been warned. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 LICENSE |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
178
|
|
|
|
|
|
|
under the same terms as Perl itself. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# vi:ts=2:sw=2:et:sta |
183
|
|
|
|
|
|
|
1; |