使用Mason作为独立的模板语言时出错

时间:2011-09-14 03:22:10

标签: perl templating mason

天儿真好,

我正在尝试使用HTML :: Mason 1.35作为独立的模板语言来生成电子邮件。请考虑以下测试脚本:

#!/usr/bin/perl
use strict;
use warnings;

use HTML::Mason::Compiler;
use HTML::Mason;
use Data::Dumper;

my $view_info = {
    name => 'John Smith',
    dob => '10-10-2010'
};

my $output;

my $mason_compiler = HTML::Mason::Compiler->new(
    allow_globals => [ qw( $view_info ) ]
);

my $mason_interpreter = HTML::Mason::Interp->new(
    compiler => $mason_compiler,
    comp_root => '/tmp/',
    out_method => \$output
);

$mason_interpreter->exec('/something.m');

print Dumper {
    output => $output
};

当我尝试运行它时,我收到以下错误:

The following parameter was passed in the call to 
HTML::Mason::Compiler::compile but was not listed in the
validation options: comp_class

Stack:
  [/usr/share/perl5/HTML/Mason/Compiler.pm:191]
  [/usr/share/perl5/HTML/Mason/ComponentSource.pm:76]
  [/usr/share/perl5/HTML/Mason/Interp.pm:452]
  [/usr/share/perl5/HTML/Mason/Request.pm:239]
  [/usr/share/perl5/HTML/Mason/Request.pm:205]
  [/usr/share/perl5/Class/Container.pm:275]
  [/usr/share/perl5/Class/Container.pm:353]
  [/usr/share/perl5/HTML/Mason/Interp.pm:348]
  [/usr/share/perl5/HTML/Mason/Interp.pm:342]
  [./masontest.pl:26]

不使用编译器,只是解释组件工作正常,但添加编译器会出现此错误。我在这里做错了什么线索?

2 个答案:

答案 0 :(得分:3)

另一种解决方案,但不是解释:使用HTML::Mason::Compiler::ToObject作为编译器而不是HTML::Mason::Compiler。我现在不记得为什么,但这就是我在工作代码中所拥有的。

答案 1 :(得分:1)

(可能的)解决方案:

#!/usr/bin/perl
use strict;
use warnings;

use HTML::Mason::Compiler;
use HTML::Mason;
use Data::Dumper;

my $view_info = {
    name => 'John Smith',
    dob => '10-10-2010'
};

my $output;

my $mason_interpreter = HTML::Mason::Interp->new(
    allow_globals => [ qw( $view_info ) ],
    comp_root => '/tmp/',
    out_method => \$output
);

$mason_interpreter->set_global('$view_info', $view_info);
$mason_interpreter->exec('/something.m');

print Dumper {
    output => $output
};