开发者

Error using Mason as stand-alone templating language

开发者 https://www.devze.com 2023-04-04 12:56 出处:网络
G\'day, I\'m trying to use HTML::Mason 1.35 as a stand-alone templating language to generate emails. Conside开发者_StackOverflow社区r the following test script:

G'day,

I'm trying to use HTML::Mason 1.35 as a stand-alone templating language to generate emails. Conside开发者_StackOverflow社区r the following test script:

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

When I try to run it, I get the following error:

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]

Not using the compiler, and just interpreting the component works fine, however adding the compiler gives this error. Any clue what I'm doing wrong here?


Another solution, but not an explanation: use HTML::Mason::Compiler::ToObject as the compiler instead of HTML::Mason::Compiler. I don't recall why at the moment, but that's what I have in my working code.


A (possible) solution:

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

精彩评论

暂无评论...
验证码 换一张
取 消