【问题标题】:Output '{{$NEXT}}' with Text::Template使用 Text::Template 输出“{{$NEXT}}”
【发布时间】:2013-05-02 00:47:33
【问题描述】:

Dist::Zilla 的 NextRelease 插件在 Changes 文件中查找 {{$NEXT}} 以放置发布日期时间信息。但是,我无法使用我的 profile.ini 生成它。这是我所拥有的:

[GenerateFile / Generate-Changes ]
filename    = Changes
is_template = 1
content = Revision history for {{$dist->name}}
content =
;todo: how can we get this to print correctly with a template?
content = {{$NEXT}}
content =   initial release

{{$dist->name}} 已正确替换为我的发行版名称,但 {{$NEXT}} 原样替换为任何内容(因为它没有被转义并且没有 $NEXT 变量)。我尝试了不同的斜线组合来转义大括号,但在使用dzil new 生成过程中,它要么没有结果,要么产生错误。我怎样才能正确地转义这个字符串,以便在dzil 使用Text::Template 处理它之后输出{{$NEXT}}

【问题讨论】:

    标签: perl plugins dist-zilla texttemplate


    【解决方案1】:

    在内容中,{{$NEXT}} 被解释为模板块,并且如您所说,想要将自己填充为缺少的 $NEXT 的内容。

    请尝试:

    content = {{'{{$NEXT}}'}}
    

    示例程序:

    use 5.14.0;
    use Text::Template 'fill_in_string';
    my $result = fill_in_string(
      q<{{'{{$NEXT}}'}}>,
      DELIMITERS => [ '{{', '}}' ],
      BROKEN => sub { die },
    );
    
    say $result;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-11
      • 1970-01-01
      • 1970-01-01
      • 2013-02-04
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      相关资源
      最近更新 更多