| 1 | package Pickles::View::MicroTemplate; | ||
| 2 | use strict; | ||
| 3 | use base qw(Pickles::View); | ||
| 4 | use Text::MicroTemplate::Extended; | ||
| 5 | |||
| 6 | __PACKAGE__->config( extension => '.mt' ); | ||
| 7 | |||
| 8 | sub new { | ||
| 9 | my $class = shift; | ||
| 10 | my $self = bless {}, $class; | ||
| 11 | $self; | ||
| 12 | } | ||
| 13 | |||
| 14 | sub render { | ||
| 15 | my( $self, $c ) = @_; | ||
| 16 | my $config = $self->merge_config( $c ); | ||
| 17 | my %args = ( | ||
| 18 | %{$c->stash}, | ||
| 19 | c => $c, | ||
| 20 | ); | ||
| 21 | my $mt = Text::MicroTemplate::Extended->new( | ||
| 22 | include_path => [ | ||
| 23 | $c->config->path_to('view'), | ||
| 24 | $c->config->path_to('view', 'inc'), | ||
| 25 | ], | ||
| 26 | %{$config}, | ||
| 27 | template_args => \%args, | ||
| 28 | ); | ||
| 29 | my $template = $c->stash->{'VIEW_TEMPLATE'}; | ||
| 30 | # $body is-a Text::MicroTemplate::EncodedString | ||
| 31 | my $body = $mt->render( $template ); | ||
| 32 | (ref $body && $body->can('as_string')) ? $body->as_string : $body; | ||
| 33 | } | ||
| 34 | |||
| 35 | 1; | ||
| 36 | |||
| 37 | __END__ |