Spoon::Template::Mason - A Spoon template module that uses Mason


Spoon-Template-Mason documentation Contained in the Spoon-Template-Mason distribution.

Index


Code Index:

NAME

Top

Spoon::Template::Mason - A Spoon template module that uses Mason

SYNOPSIS

Top

  # in your config.yaml file

  template_class: Spoon::Template::Mason

DESCRIPTION

Top

So you like Spoon/Spork/Kwiki, but you want to use Mason to generate your output. This is the module for you.

USAGE

Top

Just set "template_class" in your config.yaml file to Spoon::Template::Mason.

SUPPORT

Top

Support questions can be sent to me via email.

Please submit bugs to the CPAN RT system at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=spoon-template-mason or via email at bug-spoon-template-mason@rt.cpan.org.

AUTHOR

Top

Dave Rolsky <autarch@urth.org>

COPYRIGHT

Top


Spoon-Template-Mason documentation Contained in the Spoon-Template-Mason distribution.

package Spoon::Template::Mason;

use strict;
use warnings;
use Spoon 0.23;
use Spoon::Template '-base';

use Cwd ();
use HTML::Mason::Interp;

use vars qw ($VERSION);

$VERSION = 0.05;

field 'interp' =>
      -init => '$self->_make_interp';

sub render
{
    my $self = shift;
    my $comp = shift;

    $comp = "/$comp" unless $comp =~ m{^/};

    my $output = '';
    $self->interp->out_method(\$output);
    $self->interp->exec( $comp, $self->all, @_ );

    return $output;
}

#method private make_interp => sub
sub _make_interp
{
    my $self   = shift;
    my $params = shift || {};

    my $root_name = 'root001';
    my $path = $self->path;
    my @roots = map { [ $root_name++ => Cwd::abs_path($_) ] } ref $path ? @$path : $path;

    my $interp =
        HTML::Mason::Interp->new
            ( comp_root => \@roots,
              %$params,
            );

    $self->interp($interp);
};


1;

__END__