【问题标题】:Generating Mason output where the output lines should start with the % character生成 Mason 输出,其中输出行应以 % 字符开头
【发布时间】:2014-12-03 12:21:47
【问题描述】:

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

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

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

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

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

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

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

【问题讨论】:

  • 您是否尝试过 %% 作为逃避对行的错误解释的手段。
  • @LenJaffe 是的,当然。这是我尝试的第一件事。不工作。唯一可行的解​​决方案是编写自定义&lt;%filter&gt; :(

标签: perl mason


【解决方案1】:

基于 Mason 邮件列表的对话,唯一可行的解​​决方案是编写自定义过滤器。 (不幸的是,“自然”双精度 %% 或转义 \% 不起作用,可能永远不会添加到基本的 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 2019-03-05
    • 1970-01-01
    • 2021-11-18
    • 2022-12-09
    • 2018-04-04
    • 2018-07-31
    相关资源
    最近更新 更多