
见https://github.com/jnthn/cro-webapp
–
也可以使用“Template :: Mojo”.
这是一个Cro服务器:
use Cro::http::Router;use Cro::http::Server;use Template::Mojo;my $tmpl = slurp 'vIEws/template.tt';my $t = Template::Mojo.new($tmpl);my $application = route{ get -> '' { content 'text/HTML',$t.render({ Title => "AAA",type => "aaa",mode => "AAAaaaAAA" }); }}my Cro::Service $hello = Cro::http::Server.new: :host<localhost>,:port<10000>,:$application;$hello.start;react whenever signal(SIGINT) { $hello.stop; exit; } 模板文件如下所示:
% my %h = @_;% my $Title = %h<Title>;% my $type = %h<type>;% my $mode = %h<mode>;%<HTML> <head> <Title><%= $Title %></Title> </head> <body> <h1><%= $type %></h1> <p><%= $mode %></p> <body></HTML>
服务器代码可以做一些改造(灵感来自Bailador).添加此代码:
sub template ($template,%values){ my $tmpl = slurp "vIEws/$template"; my $t = Template::Mojo.new($tmpl); return content 'text/HTML',$t.render(%values);} 并改变“得到”:
get -> '' { template 'template.tt',{ Title => "AAA",type => "aaa",mode => "AAAaaaAAA" }; } 总结 以上是内存溢出为你收集整理的perl6 – 是否有可能将TT2与Cro一起使用?全部内容,希望文章能够帮你解决perl6 – 是否有可能将TT2与Cro一起使用?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)