| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | $self->{current}{pos} < length $self->{current}{comp_source} : | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 956 | ▶ | last if $end = $self->match_end; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 804 | ▶ | $self->match_block && next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 718 | ▶ | $self->match_named_block && next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 668 | ▶ | $self->match_substitute && next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 553 | ▶ | $self->match_code_tag && next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 491 | ▶ | $self->match_comment_tag && next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 488 | ▶ | $self->match_comp_call && next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 445 | ▶ | $self->match_perl_line && next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 444 | ▶ | $self->match_comp_content_call && next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 425 | ▶ | $self->match_comp_content_call_end && next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 406 | ▶ | $self->match_text && next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ( ( $self->{current}{in_def} || $self->{current}{in_method} ) && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->{"current"}{"in_def"} || $self->{"current"}{"in_method"} and $self->{"current"}{"comp_source"} =~ /\G\z/
$self->{"current"}{"in_def"} or $self->{"current"}{"in_method"}
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/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | $self->{current}{comp_source} =~ /\G\z/ ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $type = $self->{current}{in_def} ? 'def' : 'method'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$self->{"current"}{"in_def"} or $self->{"current"}{"in_method"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 48 | ▶ | my $type = $self->{current}{in_def} ? 'def' : 'method'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 48 | ▶ | unless ( $end =~ m,</%\Q$type\E>\n?,i ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 115 | ▶ | if ( $self->{current}{comp_source} =~ /\G(.+?)(\s*\|\s*([\w\s,]+)?\s*)?%>/igcs ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 62 | ▶ | if ( $self->{current}{comp_source} =~ /\G(.+?)%>/gcs ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 3 | ▶ | if ( $self->{current}{comp_source} =~ /\G(.*?)--%>/gcs ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | return $self->SUPER::match_perl_line(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||