首页 文章

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

提问于
浏览
2

天儿真好,

我正在尝试使用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 回答

  • 1

    另一种解决方案,但不是解释:使用 HTML::Mason::Compiler::ToObject 作为编译器而不是 HTML::Mason::Compiler . 我不知道我的工作代码中有什么 .

  • 3

    一个(可能的)解决方案:

    #!/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
    };
    

相关问题