1

使用Mason从模板(不是 Web)生成一些输出。

需要从 Mason 组件生成输出,其中输出行应以%字符开头。

因为%<space>Mason 组件中的行首是作为 perl 命令执行的,所以目前我正在使用:

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

并且 $perc 在该%init部分中定义为my $perc = '%';

上述方法有效,但对于许多行来说,这是一个糟糕的解决方案。

问题:是否有可能在某些行的开头包含“%”字符的情况下生成 Mason 输出?

4

1 回答 1

2

根据对话是 Mason 邮件列表,唯一可行的解​​决方案是编写自定义过滤器。(不幸的是,“自然”双精度%%或转义\%不起作用,可能永远不会添加到基本的 Mason 语法中。)

以下梅森过滤器有效,

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

例如从

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

将产生输出所需的输出。

%hello
% test 1
% test 2
% test 3
%hello2
于 2014-12-04T12:56:39.490 回答