Commit | Line | Data |
ed99cbb4 |
1 | package HTML::String::TT; |
2 | |
3 | use strictures 1; |
51eaef0b |
4 | |
586054e0 |
5 | BEGIN { |
6 | if ($INC{"Template.pm"} and !$INC{"UNIVERSAL/ref.pm"}) { |
7 | warn "Template was loaded before we could load UNIVERSAL::ref" |
8 | ." - this means you're probably going to get weird errors." |
9 | ." To avoid this, use HTML::String::TT before loading Template." |
10 | } |
11 | require UNIVERSAL::ref; |
12 | } |
13 | |
51eaef0b |
14 | use HTML::String; |
15 | use HTML::String::TT::Directive; |
16 | use Safe::Isa; |
ed99cbb4 |
17 | use Template; |
18 | use Template::Parser; |
19 | use Template::Stash; |
ed99cbb4 |
20 | |
21 | sub new { |
22 | shift; |
23 | Template->new( |
24 | PARSER => Template::Parser->new( |
25 | FACTORY => 'HTML::String::TT::Directive' |
26 | ), |
27 | STASH => Template::Stash->new, |
51eaef0b |
28 | FILTERS => { no_escape => sub { |
29 | $_[0]->$_isa('HTML::String::Value') |
30 | ? HTML::String::Value->new(map $_->[0], @{$_[0]->{parts}}) |
31 | : HTML::String::Value->new($_) |
32 | } }, |
77724961 |
33 | (ref($_[0]) eq 'HASH' ? %{$_[0]} : @_) |
ed99cbb4 |
34 | ); |
35 | } |
36 | |
37 | 1; |