http://perlchina.github.com/advent.perlchina.org/2011/TemplateMustache.html
=for advent_year 2011 =for advent_day 8 =for advent_title Template::Mustache =for advent_author Beckheng Lam M<Template::Mustache>是一个模板模块,它是mustache (http://mustache.github.com/) 的Perl实现版本. mustache的语法相当简洁, 有多个编程语言 (.NET, JavaScript, PHP, Python, Ruby, Java等)的实现. 因而能在多个语言中共享一个模板内容, 传入相应的数据即可. 不可过分依赖这种情形. 当然Template::Mustache的安装也较容易. 但要求Perl 5.8或之后的版本. 安装模块, 有时我会用cpanp (M<CPANPLUS>), 有时会用cpanm (M<App::cpanminus>), 这次使用前者: cpanp -i Template::Mustache 详细请参阅CPAN: M<Template::Mustache>, 下面是小例子: =begin code use strict; use Template::Mustache; my $tmpl = Template::Mustache->new(); my $strTemplateContent = "Hello {{name}}!\n"; print $tmpl->render($strTemplateContent, { 'name' => 'Beckheng' }); #output: #Hello Beckheng! my $strTemplateContent2 = "Person:\n{{#person}} {{name}}, {{age}}\n{{/person}}\n"; print $tmpl->render($strTemplateContent2, { 'person' => [ { 'name' => 'Beckheng', 'age' => 33 }, { 'name' => 'BB', 'age' => 2 }, ] }); #output: #Person: # Beckheng, 33 # BB, 2 =end code 第一次参与, 谢谢! -- Fayland Lam // http://www.fayland.org/ -- 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。 要向此网上论坛发帖,请发送电子邮件至 perlchina@googlegroups.com。 要取消订阅此网上论坛,请发送电子邮件至 perlchina+unsubscr...@googlegroups.com。 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。