App::Hachero::Plugin::Output::TT - writes results via template toolkit


App-Hachero documentation Contained in the App-Hachero distribution.

Index


Code Index:

NAME

Top

App::Hachero::Plugin::Output::TT - writes results via template toolkit

SYNOPSYS

Top

  ---
  plugins:
    - module: Output::TT
      config:
        template: /path/to/your/template
        out: /path/to/output

DESCRIPTION

Top

writes results via template toolkit

implemented hooks

* output

AUTHOR

Top

Nobuo Danjou <nobuo.danjou@gmail.com>

SEE ALSO

Top

App::Hachero

Template


App-Hachero documentation Contained in the App-Hachero distribution.

package App::Hachero::Plugin::Output::TT;
use strict;
use warnings;
use base qw(App::Hachero::Plugin::Base);
use Template;

sub output : Hook {
    my ($self, $context, $args) = @_;
    my $config = $self->config->{config};
    my $tt_file = $config->{template};
    my $out_file = $config->{out};
    my $tt = Template->new(
        ABSOLUTE => 1,
        ENCODING => 'utf8',
    ) or die $Template::ERROR;
    my $vars;
    if ($config->{stash_key} && $config->{result_key}) {
        $vars = {$config->{stash_key} => $context->result->{$config->{result_key}}};
    } else {
        $vars = $context;
    }
    my $ok = $tt->process($tt_file, $vars, $out_file, {binmode => ':utf8'});
    $ok or die $tt->error;
}

1;
__END__