gpt4 book ai didi

perl - 如何在Mojolicious模板中使用新的语法功能

转载 作者:行者123 更新时间:2023-12-04 04:17:10 25 4
gpt4 key购买 nike

我想在Mojo模板中使用花哨的后缀解引用。我想我能做

% use experimental 'postderef';

在每个模板文件的顶部,但这似乎是重复且la脚的。有什么方法可以使Mojolicious将我的编译指示导入到每个模板的词法范围内?

最佳答案

您可以使用自己的选项重新加载EPRenderer插件(默认为不带选项),选项template包含Mojo::Template的默认值。

use Mojolicious::Lite;

plugin 'EPRenderer', template => { prepend => 'use experimental "postderef";use Data::Dump "pp";'};

get '/' => sub { shift->render('index'); };

app->start;
__DATA__

@@ index.html.ep
% layout 'default';
% title 'Welcome';

Welcome to the Mojolicious real-time web framework!

% my $a = [[0]];
% push $a->[0]->@*, 1;
%= pp($a)

@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %>

</body>
</html>

关于perl - 如何在Mojolicious模板中使用新的语法功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24855798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com