« blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Plugin/Proctitle.pm
↑ Summary
blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Response.pm »
| 1 | package Dwarf::Plugin::Text::Xslate; | ||
| 2 | use Dwarf::Pragma; | ||
| 3 | use Dwarf::Util qw/add_method encode_utf8/; | ||
| 4 | use Dwarf::Util::Xslate qw/reproduce_line_feed/; | ||
| 5 | use Text::Xslate; | ||
| 6 | |||
| 7 | sub init { | ||
| 8 | my ($class, $c, $conf) = @_; | ||
| 9 | $conf ||= {}; | ||
| 10 | $conf->{path} ||= [$c->base_dir.'/tmpl']; | ||
| 11 | $conf->{cache_dir} ||= $c->base_dir.'/.xslate_cache'; | ||
| 12 | $conf->{function} ||= { | ||
| 13 | lf => reproduce_line_feed, | ||
| 14 | }; | ||
| 15 | |||
| 16 | add_method($c, render => sub { | ||
| 17 | my ($self, $template, $vars, $options) = @_; | ||
| 18 | $vars ||= {}; | ||
| 19 | $options ||= {}; | ||
| 20 | |||
| 21 | $self->call_trigger(BEFORE_RENDER => $self->handler, $self, $vars); | ||
| 22 | |||
| 23 | my $tx = Text::Xslate->new(%$conf, %$options); | ||
| 24 | my $out = $tx->render($template, $vars); | ||
| 25 | |||
| 26 | $self->call_trigger(AFTER_RENDER => $self->handler, $self, \$out); | ||
| 27 | |||
| 28 | return encode_utf8($out); | ||
| 29 | }); | ||
| 30 | } | ||
| 31 | |||
| 32 | 1; |