lib/HTML/Mason/Lexer.pm

filter: Statementstmt 94.1% 178 / 189 Branchbran 85.8% 79 / 92 Conditioncond 60.5% 23 / 38 MC/DCmcdc 40.0% 8 / 20 Subroutinesub 97.0% 33 / 34 Podpod 16.0% 4 / 25 totaltotal 81.6% 325 / 398 CC 62 SCAR 22.8
CC
62
Cov
88%
start
33.7
variable_list_block
8.1
key_val_block
7.1
CRAP 9.7
« lib/HTML/Mason/Request.pm ↑ Summary script/mason.pl »
1 # Copyright (c) 1998-2005 by Jonathan Swartz. All rights reserved.
2 # This program is free software; you can redistribute it and/or modify it
3 # under the same terms as Perl itself.
4  
5 package HTML::Mason::Lexer;
6 31 $HTML::Mason::Lexer::VERSION = '1.60';
7 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 31 ▶use HTML::Mason::Exceptions( abbr => [qw(param_error syntax_error error)] );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 31 ▶use HTML::Mason::Tools qw( taint_is_on );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 31 ▶use Params::Validate qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 0 ▶Params::Validate::validation_options( on_fail => sub { param_error join '', @_ } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
16  
17 31 ▶use Class::Container;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 31 ▶use base qw(Class::Container);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # This is a block name and what method should be called to lex its
21 # contents if it is encountered. 'def' & 'method' blocks are special
22 # cases we actually call ->start again to recursively parse the
23 # contents of a subcomponent/method. Theoretically, adding a block is
24 # as simple as adding an entry to this hash, and possibly a new
25 # contents lexing methods.
26 31 my %blocks = ( args => 'variable_list_block',
27 attr => 'key_val_block',
28 flags => 'key_val_block',
29 cleanup => 'raw_block',
30 doc => 'doc_block',
31 filter => 'raw_block',
32 init => 'raw_block',
33 once => 'raw_block',
34 perl => 'raw_block',
35 shared => 'raw_block',
36 text => 'text_block',
37 );
38  
39 sub block_names
40 31 ▶{
Subroutine block_names: called CC=1 SCAR=0.0
Pod undocumented
41 31 return keys %blocks;
42 }
43  
44 sub block_body_method
45 293 ▶{
Subroutine block_body_method: called CC=1 SCAR=0.0
Pod undocumented
46 293 return $blocks{ $_[1] };
47 }
48  
49 {
50 31 my $blocks_re;
51  
52 31 my $re = join '|', __PACKAGE__->block_names;
53 31 $blocks_re = qr/$re/i;
54  
55 sub blocks_regex
56 2821 ▶ {
Subroutine blocks_regex: called CC=1 SCAR=0.0
Pod undocumented
57 2821 return $blocks_re;
58 }
59 }
60  
61 sub lex
62 31 ▶{
Subroutine lex: called CC=4 SCAR=13.9
Pod documented
63 588 my $self = shift;
64 588 my %p = validate(@_,
65 {comp_source => SCALAR|SCALARREF,
66 name => SCALAR,
67 compiler => {isa => 'HTML::Mason::Compiler'}}
68 );
69  
70 # Note - we could improve memory usage here if we didn't make a
71 # copy of the scalarref, but that will take some more work to get
72 # it working
73 588 ▶ $p{comp_source} = ${$p{comp_source}} if ref $p{comp_source};
Branch: 1 branch
BranchTrueFalseTotal
if ref $p{"comp_source"} 588 0 588
74  
75 # Holds information about the current lex. Make it local() so
76 # we're fully re-entrant.
77 588 local $self->{current} = \%p;
78 588 my $current = $self->{current}; # For convenience
79  
80 # Clean up Mac and DOS line endings
81 588 $current->{comp_source} =~ s/\r\n?/\n/g;
82  
83 # Initialize lexer state
84 588 $current->{lines} = 1;
85 588 $current->{in_def} = $current->{in_method} = 0;
86  
87 # This will be overridden if entering a def or method section.
88 588 $current->{ending} = qr/\G\z/;
89  
90 # We need to untaint the component or else the regexes will fail
91 # to a Perl bug. The delete is important because we need to
92 # create an entirely new scalar, not just modify the existing one.
93 588 ▶ ($current->{comp_source}) = (delete $current->{comp_source}) =~ /(.*)/s
Branch: 1 branch
BranchTrueFalseTotal
if taint_is_on() 2 586 588
94 if taint_is_on;
95  
96 eval
97 588 {
98 588 $current->{compiler}->start_component;
99 588 $self->start;
100 };
101 588 my $err = $@;
102 # Always call end_component, but throw the first error
103 eval
104 588 {
105 588 $current->{compiler}->end_component;
106 };
107 588 ▶ $err ||= $@;
Condition66%2/3
$err ||= $@
l!l&&r!l&&!r
170571
MC/DC50%1/2
$err ||= $@
$err $@
Truth table66%2/3
A ||= B
A= $errB= $@
ABresult
1X1
011
000
108  
109 588 rethrow_exception $err;
110 }
111  
112 sub start
113 703 ▶{
Subroutine start: called CC=19 SCAR=35.2
Pod undocumented
114 703 my $self = shift;
115  
116 703 my $end;
117 703 while (1)
118 {
119 3506 ▶ last if $end = $self->match_end;
Branch: 1 branch
BranchTrueFalseTotal
if $end = $self->match_end 685 2821 3506
120  
121 2821 ▶ $self->match_block && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_block and next 291 2528 2819
122  
123 2528 ▶ $self->match_named_block && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_named_block and next 114 2407 2521
124  
125 2407 ▶ $self->match_substitute && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_substitute and next 409 1995 2404
126  
127 1995 ▶ $self->match_comp_call && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_comp_call and next 241 1754 1995
128  
129 1754 ▶ $self->match_perl_line && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_perl_line and next 407 1347 1754
130  
131 1347 ▶ $self->match_comp_content_call && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_comp_content_call and next 42 1305 1347
132  
133 1305 ▶ $self->match_comp_content_call_end && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_comp_content_call_end and next 36 1263 1299
134  
135 1263 ▶ $self->match_text && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_text and next 1263 0 1263
136  
137 0 ▶ if ( ( $self->{current}{in_def} || $self->{current}{in_method} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"in_def"} || $self->{"current"}{"in_method"} and $self->{"current"}{"comp_source"} =~ /\G\z/) 0 0 0
Condition0%0/6
$self->{"current"}{"in_def"} || $self->{"current"}{"in_method"} and $self->{"current"}{"comp_source"} =~ /\G\z/
!ll&&!rl&&r
000
$self->{"current"}{"in_def"} or $self->{"current"}{"in_method"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"current"}{"in_def"} || $self->{"current"}{"in_method"} and $self->{"current"}{"comp_source"} =~ /\G\z/
$self->{"current"}{"in_def"} $self->{"current"}{"in_method"} $self->{"current"}{"comp_source"} =~ /\G\z/
Truth table0%0/5
A or B and C
A= $self->{"current"}{"in_def"}B= $self->{"current"}{"in_method"}C= $self->{"current"}{"comp_source"} =~ /\G\z/
ABCresult
00X0
1X00
0100
1X11
0111
138 $self->{current}{comp_source} =~ /\G\z/ )
139 {
140 0 ▶ my $type = $self->{current}{in_def} ? 'def' : 'method';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'current'}{'in_def'} ? : 0 0 0
141 0 $self->throw_syntax_error("Missing closing </%$type> tag");
142 }
143  
144 0 ▶ last if $self->{current}{comp_source} =~ /\G\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"current"}{"comp_source"} =~ /\G\z/ 0 0 0
145  
146 # We should never get here - if we do, we're in an infinite loop.
147 0 $self->throw_syntax_error("Infinite parsing loop encountered - Lexer bug?");
148 }
149  
150 685 ▶ if ( $self->{current}{in_def} || $self->{current}{in_method} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"in_def"} or $self->{"current"}{"in_method"}) 114 571 685
Condition100%3/3
$self->{"current"}{"in_def"} or $self->{"current"}{"in_method"}
l!l&&r!l&&!r
5658571
MC/DC100%2/2
$self->{"current"}{"in_def"} or $self->{"current"}{"in_method"}
$self->{"current"}{"in_def"} $self->{"current"}{"in_method"}
Truth table100%3/3
A or B
A= $self->{"current"}{"in_def"}B= $self->{"current"}{"in_method"}
ABresult
1X1
011
000
151 {
152 114 ▶ my $type = $self->{current}{in_def} ? 'def' : 'method';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'current'}{'in_def'} ? : 56 58 114
153 114 ▶ unless ( $end =~ m,</%\Q$type\E>\n?,i )
Branch: 1 branch
BranchTrueFalseTotal
unless ($end =~ m[</%\Q$type\E>\n?]i) 0 114 114
154 {
155 0 my $block_name = $self->{current}{"in_$type"};
156 0 $self->throw_syntax_error("No </%$type> tag for <%$type $block_name> block");
157 }
158 }
159 }
160  
161 sub match_block
162 2821 ▶{
Subroutine match_block: called CC=2 SCAR=6.9
Pod undocumented
163 2821 my $self = shift;
164  
165 2821 my $blocks_re = $self->blocks_regex;
166  
167 2821 ▶ if ( $self->{current}{comp_source} =~ /\G<%($blocks_re)>/igcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"comp_source"} =~ /\G<%($blocks_re)>/cgis) 293 2528 2821
168 {
169 293 my $type = lc $1;
170 293 $self->{current}{compiler}->start_block( block_type => $type );
171  
172 293 my $method = $self->block_body_method($type);
173 293 $self->$method( {block_type => $type} );
174  
175 291 return 1;
176 }
177 }
178  
179 sub generic_block
180 187 ▶{
Subroutine generic_block: called CC=2 SCAR=6.9
Pod undocumented
181 187 my ($self, $method, $p) = @_;
182  
183 187 $p->{allow_text} = 1;
184 187 my ($block, $nl) = $self->match_block_end( $p );
185  
186 $self->{current}{compiler}->$method( block_type => $p->{block_type},
187 187 block => $block );
188  
189 187 $self->{current}{lines} += $block =~ tr/\n//;
190 187 ▶ $self->{current}{lines}++ if $nl;
Branch: 1 branch
BranchTrueFalseTotal
if $nl 183 4 187
191  
192 187 $self->{current}{compiler}->end_block( block_type => $p->{block_type} );
193 }
194  
195 sub text_block
196 2 ▶{
Subroutine text_block: called CC=1 SCAR=0.0
Pod undocumented
197 2 my $self = shift;
198 2 $self->generic_block('text_block', @_);
199 }
200  
201 sub raw_block
202 183 ▶{
Subroutine raw_block: called CC=1 SCAR=0.0
Pod undocumented
203 183 my $self = shift;
204 183 $self->generic_block('raw_block', @_);
205 }
206  
207 sub doc_block
208 2 ▶{
Subroutine doc_block: called CC=1 SCAR=0.0
Pod undocumented
209 2 my $self = shift;
210 2 $self->generic_block('doc_block', @_);
211 }
212  
213 sub variable_list_block
214 61 ▶{
Subroutine variable_list_block: called CC=8 SCAR=20.9
Pod undocumented
215 61 my ($self, $p) = @_;
216  
217 61 my $ending = qr/ \n | <\/%\Q$p->{block_type}\E> /ix;
218 61 ▶ while ( $self->{current}{comp_source} =~ m,
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"comp_source"} =~ m[ \G # last pos matched (?: [ \t]* ( [\$\@\%] ) # variable type ( [^\W\d]\w* ) # only allows valid Perl variable names [ \t]* # if we have a default arg we'll suck up # any comment it has as part of the default # otherwise explcitly search for a comment (?: (?: # this entire entire piece is optional => ( [^\n]+? ) # default value ) | (?: # an optional comment [ \t]* \# [^\n]* ) )? (?= $ending ) | [ \t]* # a comment line \# [^\n]* (?= $ending ) | [ \t]* # just space ) (\n | # newline or (?= <\/%\Q$p->{"block_type"}\E> ) ) # end of block (don't consume it) ]cgix) 213 61 274
219 \G # last pos matched
220 (?:
221 [ \t]*
222 ( [\$\@\%] ) # variable type
223 ( [^\W\d]\w* ) # only allows valid Perl variable names
224 [ \t]*
225 # if we have a default arg we'll suck up
226 # any comment it has as part of the default
227 # otherwise explcitly search for a comment
228 (?:
229 (?: # this entire entire piece is optional
230 =>
231 ( [^\n]+? ) # default value
232 )
233 |
234 (?: # an optional comment
235 [ \t]*
236 \#
237 [^\n]*
238 )
239 )?
240 (?= $ending )
241 |
242 [ \t]* # a comment line
243 \#
244 [^\n]*
245 (?= $ending )
246 |
247 [ \t]* # just space
248 )
249 (\n | # newline or
250 (?= <\/%\Q$p->{block_type}\E> ) ) # end of block (don't consume it)
251 ,ixgc
252 )
253 {
254 213 ▶ if ( defined $1 && defined $2 && length $1 && length $2 )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1 and defined $2 and length $1 and length $2) 95 118 213
Condition66%6/9
defined $1 and defined $2 and length $1 and length $2
!ll&&!rl&&r
118095
defined $1 and defined $2 and length $1
!ll&&!rl&&r
118095
defined $1 and defined $2
!ll&&!rl&&r
118095
MC/DC25%1/4
defined $1 and defined $2 and length $1 and length $2
defined $1 defined $2 length $1 length $2
Truth table40%2/5
A and B and C and D
A= defined $1B= defined $2C= length $1D= length $2
ABCDresult
0XXX0
10XX0
110X0
11100
11111
255 {
256 $self->{current}{compiler}->variable_declaration( block_type => $p->{block_type},
257 95 type => $1,
258 name => $2,
259 default => $3,
260 );
261 }
262  
263 213 ▶ $self->{current}{lines}++ if $4;
Branch: 1 branch
BranchTrueFalseTotal
if $4 149 64 213
264 }
265  
266 61 $p->{allow_text} = 0;
267 61 my $nl = $self->match_block_end( $p );
268 59 ▶ $self->{current}{lines}++ if $nl;
Branch: 1 branch
BranchTrueFalseTotal
if $nl 56 3 59
269  
270 59 $self->{current}{compiler}->end_block( block_type => $p->{block_type} );
271 }
272  
273 sub key_val_block
274 45 ▶{
Subroutine key_val_block: called CC=7 SCAR=19.6
Pod undocumented
275 45 my ($self, $p) = @_;
276  
277 45 my $ending = qr, (?: \n | # newline or
278 (?= </%\Q$p->{block_type}\E> ) ) # end of block (don't consume it)
279 ,ix;
280  
281 45 ▶ while ( $self->{current}{comp_source} =~ /
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"comp_source"} =~ / \G [ \t]* ([\w_]+) # identifier [ \t]*=>[ \t]* # separator (\S[^\n]*?) # value ( must start with a non-space char) $ending | \G\n # a plain empty line | \G [ \t]* # an optional comment \# [^\n]* $ending | \G[ \t]+? $ending /cgx) 107 45 152
282 \G
283 [ \t]*
284 ([\w_]+) # identifier
285 [ \t]*=>[ \t]* # separator
286 (\S[^\n]*?) # value ( must start with a non-space char)
287 $ending
288 |
289 \G\n # a plain empty line
290 |
291 \G
292 [ \t]* # an optional comment
293 \#
294 [^\n]*
295 $ending
296 |
297 \G[ \t]+?
298 $ending
299 /xgc )
300 {
301 107 ▶ if ( defined $1 && defined $2 && length $1 && length $2 )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1 and defined $2 and length $1 and length $2) 62 45 107
Condition66%6/9
defined $1 and defined $2 and length $1 and length $2
!ll&&!rl&&r
45062
defined $1 and defined $2 and length $1
!ll&&!rl&&r
45062
defined $1 and defined $2
!ll&&!rl&&r
45062
MC/DC25%1/4
defined $1 and defined $2 and length $1 and length $2
defined $1 defined $2 length $1 length $2
Truth table40%2/5
A and B and C and D
A= defined $1B= defined $2C= length $1D= length $2
ABCDresult
0XXX0
10XX0
110X0
11100
11111
302 {
303 $self->{current}{compiler}->key_value_pair( block_type => $p->{block_type},
304 62 key => $1,
305 value => $2
306 );
307 }
308  
309 107 $self->{current}{lines}++;
310 }
311  
312 45 $p->{allow_text} = 0;
313 45 my $nl = $self->match_block_end( $p );
314 45 ▶ $self->{current}{lines}++ if $nl;
Branch: 1 branch
BranchTrueFalseTotal
if $nl 44 1 45
315  
316 45 $self->{current}{compiler}->end_block( block_type => $p->{block_type} );
317 }
318  
319 sub match_block_end
320 293 ▶{
Subroutine match_block_end: called CC=4 SCAR=13.9
Pod undocumented
321 293 my ($self, $p) = @_;
322  
323 293 ▶ my $re = $p->{allow_text} ? qr,\G(.*?)</%\Q$p->{block_type}\E>(\n?),is
Branch: 1 branch
BranchTrueFalseTotal
$p->{'allow_text'} ? : 187 106 293
324 : qr,\G\s*</%\Q$p->{block_type}\E>(\n?),is;
325 293 ▶ if ( $self->{current}{comp_source} =~ /$re/gc )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'current'}{'comp_source'} =~ /$re/cg) { } 291 2 293
326 {
327 291 ▶ return $p->{allow_text} ? ($1, $2) : $1;
Branch: 1 branch
BranchTrueFalseTotal
$p->{'allow_text'} ? : 187 104 291
328 }
329 else
330 {
331 2 $self->throw_syntax_error("Invalid <%$p->{block_type}> section line");
332 }
333 }
334  
335 sub match_named_block
336 2528 ▶{
Subroutine match_named_block: called CC=4 SCAR=13.9
Pod undocumented
337 2528 my ($self, $p) = @_;
338  
339 2528 ▶ if ( $self->{current}{comp_source} =~ /\G<%(def|method)(?:\s+([^\n]+?))?\s*>/igcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"comp_source"} =~ /\G<%(def|method)(?:\s+([^\n]+?))?\s*>/cgis) 121 2407 2528
340 {
341 121 my ($type, $name) = (lc $1, $2);
342  
343 121 ▶ $self->throw_syntax_error("$type block without a name")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 1 120 121
Condition66%2/3
defined $name and length $name
!ll&&!rl&&r
10120
MC/DC50%1/2
defined $name and length $name
defined $name length $name
Truth table66%2/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
344 unless defined $name && length $name;
345  
346 120 $self->{current}{compiler}->start_named_block( block_type => $type,
347 name => $name );
348  
349 # This will cause ->start to return once it hits the
350 # appropriate ending tag.
351 115 local $self->{current}{ending} = qr,\G</%\Q$type\E>\n?,i;
352  
353 115 local $self->{current}{"in_$type"} = $name;
354  
355 115 $self->start();
356  
357 114 $self->{current}{compiler}->end_named_block( block_type => $type );
358  
359 114 return 1;
360 }
361 }
362  
363 # Like [a-zA-Z_] but respects locales
364 31 my $flag = qr/[[:alpha:]_]\w*/;
365 832 ▶sub escape_flag_regex { $flag }
Subroutine escape_flag_regex: called CC=1 SCAR=0.0
Pod undocumented
366  
367 sub match_substitute
368 2407 ▶{
Subroutine match_substitute: called CC=4 SCAR=13.9
Pod undocumented
369 # This routine relies on there *not* to be an opening <%foo> tag
370 # present, so match_block() must happen first.
371
372 2407 my $self = shift;
373  
374 2407 ▶ return 0 unless $self->{current}{comp_source} =~ /\G<%/gcs;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"current"}{"comp_source"} =~ /\G<%/cgs 1995 412 2407
375  
376 412 ▶ if ( $self->{current}{comp_source} =~
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'current'}{'comp_source'} =~ / \G (.+?) # Substitution body ($1) ( \s* (?<!\|) # Not preceded by a '|' \| # A '|' \s* ( # (Start $3) $flag # A flag (?:\s*,\s*$flag)* # More flags, with comma separators ) \s* )? %> # Closing tag /cgisx) { } 409 3 412
377 m{
378 \G
379 (.+?) # Substitution body ($1)
380 (
381 \s*
382 (?<!\|) # Not preceded by a '|'
383 \| # A '|'
384 \s*
385 ( # (Start $3)
386 $flag # A flag
387 (?:\s*,\s*$flag)* # More flags, with comma separators
388 )
389 \s*
390 )?
391 %> # Closing tag
392 }xcigs )
393 {
394 409 $self->{current}{lines} += tr/\n// foreach grep defined, ($1, $2);
395  
396 409 $self->{current}{compiler}->substitution( substitution => $1,
397 escape => $3 );
398 409 return 1;
399 }
400 else
401 {
402 3 $self->throw_syntax_error("'<%' without matching '%>'");
403 }
404 }
405  
406 sub match_comp_call
407 1995 ▶{
Subroutine match_comp_call: called CC=3 SCAR=11.1
Pod undocumented
408 1995 my $self = shift;
409  
410 1995 ▶ if ( $self->{current}{comp_source} =~ /\G<&(?!\|)/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"comp_source"} =~ /\G<&(?!\|)/cgs) 241 1754 1995
411 {
412 241 ▶ if ( $self->{current}{comp_source} =~ /\G(.*?)&>/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'current'}{'comp_source'} =~ /\G(.*?)&>/cgs) { } 241 0 241
413 {
414 241 my $call = $1;
415 241 $self->{current}{compiler}->component_call( call => $call );
416 241 $self->{current}{lines} += $call =~ tr/\n//;
417  
418 241 return 1;
419 }
420 else
421 {
422 0 $self->throw_syntax_error("'<&' without matching '&>'");
423 }
424 }
425 }
426  
427  
428 sub match_comp_content_call
429 1347 ▶{
Subroutine match_comp_content_call: called CC=3 SCAR=11.1
Pod undocumented
430 1347 my $self = shift;
431  
432 1347 ▶ if ( $self->{current}{comp_source} =~ /\G<&\|/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"comp_source"} =~ /\G<&\|/cgs) 42 1305 1347
433 {
434 42 ▶ if ( $self->{current}{comp_source} =~ /\G(.*?)&>/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'current'}{'comp_source'} =~ /\G(.*?)&>/cgs) { } 42 0 42
435 {
436 42 my $call = $1;
437 42 $self->{current}{compiler}->component_content_call( call => $call );
438 42 $self->{current}{lines} += $call =~ tr/\n//;
439  
440 42 return 1;
441 }
442 else
443 {
444 0 $self->throw_syntax_error("'<&|' without matching '&>'");
445 }
446 }
447 }
448  
449 sub match_comp_content_call_end
450 1305 ▶{
Subroutine match_comp_content_call_end: called CC=3 SCAR=11.0
Pod undocumented
451 1305 my $self = shift;
452  
453 1305 ▶ if ( $self->{current}{comp_source} =~ m,\G</&(.*?)>,gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"comp_source"} =~ m[\G</&(.*?)>]cgs) 42 1263 1305
454 {
455 42 ▶ my $call = $1 || '';
Condition100%2/2
$1 || ''
l!l
735
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
456 42 $self->{current}{compiler}->component_content_call_end( call_end => $call );
457 36 $self->{current}{lines} += $call =~ tr/\n//;
458  
459 36 return 1;
460 }
461 }
462  
463 sub match_perl_line
464 1754 ▶{
Subroutine match_perl_line: called CC=2 SCAR=6.9
Pod undocumented
465 1754 my $self = shift;
466  
467 1754 ▶ if ( $self->{current}{comp_source} =~ /\G(?<=^)%([^\n]*)(?:\n|\z)/gcm )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"comp_source"} =~ /\G(?<=^)%([^\n]*)(?:\n|\z)/cgm) 407 1347 1754
468 {
469 407 $self->{current}{compiler}->perl_line( line => $1 );
470 407 $self->{current}{lines}++;
471  
472 407 return 1;
473 }
474 }
475  
476 sub match_text
477 1263 ▶{
Subroutine match_text: called CC=4 SCAR=14.1
Pod undocumented
478 1263 my $self = shift;
479 1263 my $c = $self->{current};
480  
481 # Most of these terminator patterns actually belong to the next
482 # lexeme in the source, so we use a lookahead if we don't want to
483 # consume them. We use a lookbehind when we want to consume
484 # something in the matched text, like the newline before a '%'.
485 1263 ▶ if ( $c->{comp_source} =~ m{
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"comp_source"} =~ m[ \G (.*?) # anything, followed by: ( (?<=\n)(?=%) # an eval line - consume the \n | (?=</?[%&]) # a substitution or block or call start or end # - don't consume | \\\n # an escaped newline - throw away | \z # end of string ) ]cgsx) 1263 0 1263
486 \G
487 (.*?) # anything, followed by:
488 (
489 (?<=\n)(?=%) # an eval line - consume the \n
490 |
491 (?=</?[%&]) # a substitution or block or call start or end
492 # - don't consume
493 |
494 \\\n # an escaped newline - throw away
495 |
496 \z # end of string
497 )
498 }xcgs )
499 {
500 # Note: to save memory, it might be preferable to break very
501 # large $1 strings into several pieces and pass the pieces to
502 # compiler->text(). In my testing, this was quite a bit
503 # slower, though. -Ken 2002-09-19
504 1263 ▶ $c->{compiler}->text( text => $1 ) if length $1;
Branch: 1 branch
BranchTrueFalseTotal
if length $1 1202 61 1263
505 # Not checking definedness seems to cause extra lines to be
506 # counted with Perl 5.00503. I'm not sure why - dave
507 1263 $c->{lines} += tr/\n// foreach grep defined, ($1, $2);
508  
509 1263 return 1;
510 }
511
512 0 return 0;
513 }
514  
515 sub match_end
516 3506 ▶{
Subroutine match_end: called CC=4 SCAR=13.9
Pod undocumented
517 3506 my $self = shift;
518  
519 # $self->{current}{ending} is a qr// 'string'. No need to escape. It will
520 # also include the needed \G marker
521 3506 ▶ if ( $self->{current}{comp_source} =~ /($self->{current}{ending})/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"comp_source"} =~ /($self->{"current"}{"ending"})/cgs) 685 2821 3506
522 {
523 685 $self->{current}{lines} += $1 =~ tr/\n//;
524 685 ▶ return defined $1 && length $1 ? $1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 && length $1 ? : 114 571 685
Condition66%2/3
defined $1 and length $1
!ll&&!rl&&r
0571114
MC/DC50%1/2
defined $1 and length $1
defined $1 length $1
Truth table66%2/3
A and B
A= defined $1B= length $1
ABresult
0X0
100
111
525 }
526 2821 return 0;
527 }
528  
529 # goes from current pos, skips a newline if its the next character,
530 # and then goes to the next newline. Alternately, the caller can
531 # provide a starting position.
532 sub _next_line
533 19 ▶{
Subroutine _next_line: called CC=4 SCAR=13.9
534 19 my $self = shift;
535 19 my $pos = shift;
536  
537 $pos = ( defined $pos ?
538 $pos :
539 ( substr( $self->{current}{comp_source}, pos($self->{current}{comp_source}), 1 ) eq "\n" ?
540 pos($self->{current}{comp_source}) + 1 :
541 19 ▶ pos($self->{current}{comp_source}) ) );
Branch: 2 branches
BranchTrueFalseTotal
defined $pos ? : 0 19 19
substr($self->{'current'}{'comp_source'}, pos $self->{'current'}{'comp_source'}, 1) eq "\n" ? : 16 3 19
542  
543 my $to_eol = ( index( $self->{current}{comp_source}, "\n", $pos ) != -1 ?
544 ( index( $self->{current}{comp_source}, "\n" , $pos ) ) - $pos :
545 19 ▶ length $self->{current}{comp_source} );
Branch: 1 branch
BranchTrueFalseTotal
index($self->{'current'}{'comp_source'}, "\n", $pos) != -1 ? : 15 4 19
546 19 return substr( $self->{current}{comp_source}, $pos, $to_eol );
547 }
548  
549 sub line_number
550 4836 ▶{
Subroutine line_number: called CC=1 SCAR=0.0
Pod documented
551 4836 my $self = shift;
552  
553 4836 return $self->{current}{lines};
554 }
555  
556 sub name
557 2318 ▶{
Subroutine name: called CC=1 SCAR=0.0
Pod documented
558 2318 my $self = shift;
559  
560 2318 return $self->{current}{name};
561 }
562  
563 sub throw_syntax_error
564 19 ▶{
Subroutine throw_syntax_error: called CC=1 SCAR=0.0
Pod documented
565 19 my ($self, $error) = @_;
566  
567 19 HTML::Mason::Exception::Syntax->throw( error => $error,
568 comp_name => $self->name,
569 source_line => $self->_next_line,
570 line_number => $self->line_number );
571 }
572  
573 31 1;
574  
575 __END__
« lib/HTML/Mason/Request.pm ↑ Summary script/mason.pl »