Search code examples
perltemplatingmason

Error using Mason as stand-alone templating language


G'day,

I'm trying to use HTML::Mason 1.35 as a stand-alone templating language to generate emails. Consider 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?


Solution

  • 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.