Generating Mason output where the output lines should start with the % character

86 views Asked by At

Using Mason for generate some output from templates (not web).

Need generate an output from the Mason component where the output lines should start with the % character.

Because the %<space> at the beginning of the lines in the Mason component are executed as perl commands, currently I'm using:

<% $perc %> the remaining content of the line.

and the $perc is defined in the %init section as my $perc = '%';

The above works, but for many lines it is an terrible solution.

The question: Is it possible somewhat generate Mason output where some lines contains the '%' character at the beginning of the line?

1

There are 1 answers

0
clt60 On

Based on the conversation is the Mason mailing list, the only working solution is write an custom filter. (unfortunately the "natural" double %% or escaped \% didn't works and probably will be never added into basic Mason syntax.)

The following Mason filter works,

<%filter unesperc><% $yield->() =~ s/^\\%/%/gmr %></%filter>

e.g. from the

% $.unesperc {{
\%hello
% for my $i (1..3) {
\% test <% $i %>
% }
\%hello2
% }}

will produce output the wanted output.

%hello
% test 1
% test 2
% test 3
%hello2