use UNIVERSAL::ref to make TT internals be less stupid
[scpubgit/HTML-String.git] / lib / HTML / String / TT.pm
1 package HTML::String::TT;
2
3 use strictures 1;
4
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
14 use HTML::String;
15 use HTML::String::TT::Directive;
16 use Safe::Isa;
17 use Template;
18 use Template::Parser;
19 use Template::Stash;
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,
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         } },
33         (ref($_[0]) eq 'HASH' ? %{$_[0]} : @_)
34     );
35 }
36
37 1;