Fuse::Template::TT - Read template files


Fuse-Template documentation Contained in the Fuse-Template distribution.

Index


Code Index:

NAME

Top

Fuse::Template::TT - Read template files

ATTRIBUTES

Top

vars

Holds a hash ref with the variables which is available in the template.

paths

Holds an array ref with paths to where Template::Toolkit will look for templates.

METHODS

Top

render

    $text = $self->render($vfile);

Will return the output from a processed template. The $vfile points to a template relative to one of the paths. It cannot start with "/".

$text will hold the error message if templat toolkit fail to render the template.

process

See Template.

error

See Template.

AUTHOR

Top

See Fuse::Template.


Fuse-Template documentation Contained in the Fuse-Template distribution.
package Fuse::Template::TT;

use Moose;
use Template;

has vars => (
    is => 'ro',
    isa => 'HashRef',
    default => sub { {} },
);

has paths => (
    is => 'ro',
    isa => 'ArrayRef',
    default => sub { [] },
);

has _template => (
    is => 'ro',
    isa => 'Object',
    lazy_build => 1,
    handles => [qw/process error/],
);

sub _build__template {
    return Template->new(
        INCLUDE_PATH => $_[0]->paths,
        EVAL_PERL => 0,
        TEMPLATE_EXTENSION => 'tt',
    );
}

sub render {
    my $self = shift;
    my $vfile = shift;
    my $text;
    
    $self->process($vfile, $self->vars, \$text);

    return $text ? $text : $self->error;
}

1;