add strictures commit (out of order)
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / FilterBuilder / Template.pm
CommitLineData
9e219709 1package HTML::Zoom::FilterBuilder;
2
1cf03540 3use strictures 1;
9e219709 4use Template::Tiny;
5
6sub _template_object {
7 shift->{_template_object} ||= Template::Tiny->new;
8}
9
10sub template_text {
11 my ($self, $vars) = @_;
12 my $parser = $self->_zconfig->parser;
13 my $tt = $self->_template_object;
14 $self->collect({
15 filter => sub {
16 $_->map(sub {
17 return $_ unless $_->{type} eq 'TEXT';
18 my $unescape = $parser->html_unescape($_->{raw});
19 $tt->process(\$unescape, $vars, \my $out);
20 return { %$_, raw => $parser->html_escape($out) }
21 })
22 },
23 passthrough => 1,
24 })
25}
26
27sub template_text_raw {
28 my ($self, $vars) = @_;
29 my $tt = $self->_template_object;
30 my $parser = $self->_zconfig->parser;
31 $self->collect({
32 filter => sub {
33 $_->map(sub {
34 return $_ unless $_->{type} eq 'TEXT';
35 $tt->process(\($_->{raw}), $vars, \my $out);
36 return { %$_, raw => $out }
37 })
38 },
39 passthrough => 1,
40 })
41}
42
431;