The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


MasonX::Lexer::MSP - Give Mason a more ASP/JSP compatible syntax


    my $interp = HTML::Mason::Interp->new( 
                 data_dir => '/here',
                 comp_root => '/there',
                 lexer_class => 'MasonX::Lexer::MSP',


This lexer makes changes to the Mason syntax to make it closer to the syntax used by ASP and JSP. These changes are incompatible with the default Mason syntax, unfortunately.

Syntax Changes

The in-line code tag used by ASP and JSP is this: (which conflicts with Mason's default substitution tag)

    <% $var = 'perl code'; %>

The substitution tag is this:

    <%= $var %>

Perl-lines are disabled by default. I consider them syntactically dangerous, but if you like them you can have them back by setting the 'perl_lines' parameter to 1.

    my $interp = HTML::Mason::Interp->new( 
                 data_dir => '/here',
                 comp_root => '/there',
                 lexer_class => 'HTML::Mason::Lexer::MSP',
                 perl_lines => 1,

The last addition is JSP-style hidden comments, which begin with '<%--' and end with '--%>'. The comments do not appear in the component output, similar to a <%doc> section. The comment may contain any text except the ending tag. If you need to put the ending tag in, escape the last character like this: '--%\>'.

    <%-- this text will not appear in the output --%>

Other Syntax

Everything else is the same.


John Williams, <>