blib/lib/MasonX/Lexer/MSP.pm

filter: Statementstmt 85.9% 61 / 71 Branchbran 78.8% 41 / 52 Conditioncond 33.3% 3 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 5 totaltotal 76.4% 117 / 153 CC 30 SCAR 30.0
CC
30
Cov
80%
start
34.3
match_substitute
4.0
match_code_tag
3.0
CRAP 20.0
↑ Summary
1 package MasonX::Lexer::MSP;
2  
3 # Written by John Williams. Most code is plagurized from Lexer.pm, which is:
4 # Copyright (c) 1998-2004 by Jonathan Swartz. All rights reserved.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the same terms as Perl itself.
7  
8 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 our $VERSION = '0.11';
11 7 ▶use base qw(HTML::Mason::Lexer);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 7 ▶use HTML::Mason::Exceptions( abbr => [qw(param_error syntax_error error)] );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 ▶use Params::Validate qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 0 ▶Params::Validate::validation_options( on_fail => sub { param_error join '', @_ } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
17  
18  
19 7 __PACKAGE__->valid_params (
20 perl_lines => { parse => 'boolean', type => BOOLEAN, default => 0,
21 descr => "Allow perl-lines to be used", },
22 );
23  
24  
25 sub start
26 156 ▶{
Subroutine start: called CC=22 SCAR=35.4
Pod undocumented
27 156 my $self = shift;
28  
29 156 my $end;
30 156 ▶ while ( defined $self->{current}{pos} ?
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{"current"}{"pos"} ? $self->{"current"}{"pos"} < length $self->{"current"}{"comp_source"} : 1) 956 0 956
defined $self->{'current'}{'pos'} ? : 0 956 956
31 $self->{current}{pos} < length $self->{current}{comp_source} :
32 1 )
33 {
34 956 ▶ last if $end = $self->match_end;
Branch: 1 branch
BranchTrueFalseTotal
if $end = $self->match_end 152 804 956
35  
36 804 ▶ $self->match_block && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_block and next 84 718 802
37  
38 718 ▶ $self->match_named_block && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_named_block and next 48 668 716
39  
40 668 ▶ $self->match_substitute && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_substitute and next 115 553 668
41  
42 553 ▶ $self->match_code_tag && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_code_tag and next 62 491 553
43  
44 491 ▶ $self->match_comment_tag && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_comment_tag and next 3 488 491
45  
46 488 ▶ $self->match_comp_call && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_comp_call and next 43 445 488
47  
48 445 ▶ $self->match_perl_line && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_perl_line and next 1 444 445
49  
50 444 ▶ $self->match_comp_content_call && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_comp_content_call and next 19 425 444
51  
52 425 ▶ $self->match_comp_content_call_end && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_comp_content_call_end and next 19 406 425
53  
54 406 ▶ $self->match_text && next;
Branch: 1 branch
BranchTrueFalseTotal
$self->match_text and next 406 0 406
55  
56 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
57 $self->{current}{comp_source} =~ /\G\z/ )
58 {
59 0 ▶ my $type = $self->{current}{in_def} ? 'def' : 'method';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'current'}{'in_def'} ? : 0 0 0
60 0 $self->throw_syntax_error("Missing closing </%$type> tag");
61 }
62  
63 # We should never get here - if we do, we're in an infinite loop.
64 0 $self->throw_syntax_error("Infinite parsing loop encountered - Lexer bug?");
65 }
66  
67 152 ▶ if ( $self->{current}{in_def} || $self->{current}{in_method} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"in_def"} or $self->{"current"}{"in_method"}) 48 104 152
Condition100%3/3
$self->{"current"}{"in_def"} or $self->{"current"}{"in_method"}
l!l&&r!l&&!r
1236104
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
68 {
69 48 ▶ my $type = $self->{current}{in_def} ? 'def' : 'method';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'current'}{'in_def'} ? : 12 36 48
70 48 ▶ unless ( $end =~ m,</%\Q$type\E>\n?,i )
Branch: 1 branch
BranchTrueFalseTotal
unless ($end =~ m[</%\Q$type\E>\n?]i) 0 48 48
71 {
72 0 my $block_name = $self->{current}{"in_$type"};
73 0 $self->throw_syntax_error("No </%$type> tag for <%$type $block_name> block");
74 }
75 }
76 }
77  
78  
79 sub match_substitute
80 668 ▶{
Subroutine match_substitute: called CC=4 SCAR=14.0
Pod undocumented
81 668 my $self = shift;
82  
83 668 ▶ if ( $self->{current}{comp_source} =~ /\G<%=/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"comp_source"} =~ /\G<%=/cgs) 115 553 668
84 {
85 115 ▶ if ( $self->{current}{comp_source} =~ /\G(.+?)(\s*\|\s*([\w\s,]+)?\s*)?%>/igcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'current'}{'comp_source'} =~ /\G(.+?)(\s*\|\s*([\w\s,]+)?\s*)?%>/cgis) { } 115 0 115
86 {
87 115 my ($sub, $escape) = ($1, $3);
88 115 $self->{current}{compiler}->substitution( substitution => $sub,
89 escape => $escape );
90  
91 # Add it in just to count lines
92 115 ▶ $sub .= $2 if $2;
Branch: 1 branch
BranchTrueFalseTotal
if $2 13 102 115
93 115 $self->{current}{lines} += $sub =~ tr/\n/\n/;
94  
95 115 return 1;
96 }
97 else
98 {
99 0 $self->throw_syntax_error("'<%=' without matching '%>'");
100 }
101 }
102 }
103  
104 # match <% code %>
105 # '<%' should not be immediately followed by '=', '|', '&', or '-'
106 # '=' is substitution, '-' is comments,
107 # '|' and '&' might be used for components calls in the future
108 # Actually a space is preferred: i.e. '<% '
109 sub match_code_tag
110 553 ▶{
Subroutine match_code_tag: called CC=3 SCAR=11.1
Pod undocumented
111 553 my $self = shift;
112  
113 553 ▶ if ( $self->{current}{comp_source} =~ /\G<%(?![=|&-])/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"comp_source"} =~ /\G<%(?![=|&-])/cgs) 62 491 553
114 {
115 62 ▶ if ( $self->{current}{comp_source} =~ /\G(.+?)%>/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'current'}{'comp_source'} =~ /\G(.+?)%>/cgs) { } 62 0 62
116 {
117 62 my $code = $1;
118 62 $self->{current}{compiler}->raw_block( block_type => 'perl',
119 block => $code );
120  
121 # count lines
122 62 $self->{current}{lines} += $code =~ tr/\n/\n/;
123  
124 62 return 1;
125 }
126 else
127 {
128 0 $self->throw_syntax_error("'<%' without matching '%>'");
129 }
130 }
131 }
132  
133 sub match_comment_tag
134 491 ▶{
Subroutine match_comment_tag: called CC=3 SCAR=11.1
Pod undocumented
135 491 my $self = shift;
136  
137 491 ▶ if ( $self->{current}{comp_source} =~ /\G<%--/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current"}{"comp_source"} =~ /\G<%--/cgs) 3 488 491
138 {
139 3 ▶ if ( $self->{current}{comp_source} =~ /\G(.*?)--%>/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'current'}{'comp_source'} =~ /\G(.*?)--%>/cgs) { } 3 0 3
140 {
141 3 my $comment = $1;
142 3 $self->{current}{compiler}->doc_block( block_type => 'doc',
143 block => $comment );
144  
145 3 $self->{current}{lines} += $comment =~ tr/\n/\n/;
146  
147 3 return 1;
148 }
149 else
150 {
151 0 $self->throw_syntax_error("'<%--' without matching '--%>'");
152 }
153 }
154 }
155  
156  
157 sub match_perl_line
158 445 ▶{
Subroutine match_perl_line: called CC=2 SCAR=6.9
Pod undocumented
159 445 my $self = shift;
160  
161 445 ▶ return 0 unless $self->{perl_lines};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"perl_lines"} 440 5 445
162  
163 5 return $self->SUPER::match_perl_line(@_);
164 }
165  
166  
167 7 1;
168  
169 __END__
↑ Summary