X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FHTML%2FString%2FTT.pm;h=0244de808da2b403044f7b2eba52c444297e212c;hb=4f4204a3cb10eac31bb4387275f10753d25bf07e;hp=fb1f1cb9df02ef0acf1b95649eca6a7411136818;hpb=ed99cbb44b0589b147076f6874c331818db44b83;p=scpubgit%2FHTML-String.git diff --git a/lib/HTML/String/TT.pm b/lib/HTML/String/TT.pm index fb1f1cb..0244de8 100644 --- a/lib/HTML/String/TT.pm +++ b/lib/HTML/String/TT.pm @@ -1,10 +1,32 @@ package HTML::String::TT; use strictures 1; + +BEGIN { + if ($INC{"Template.pm"} and !$INC{"UNIVERSAL/ref.pm"}) { + warn "Template was loaded before we could load UNIVERSAL::ref" + ." - this means you're probably going to get weird errors." + ." To avoid this, use HTML::String::TT before loading Template." + } + require UNIVERSAL::ref; +} + +use HTML::String; +use HTML::String::TT::Directive; +use Safe::Isa; use Template; use Template::Parser; use Template::Stash; -use HTML::String::TT::Directive; + +BEGIN { + my $orig_blessed = Template::Stash->can('blessed'); + no warnings 'redefine'; + *Template::Stash::blessed = sub ($) { + my $val = $orig_blessed->($_[0]); + return undef if defined($val) and $val eq 'HTML::String::Value'; + return $val; + }; +} sub new { shift; @@ -13,8 +35,107 @@ sub new { FACTORY => 'HTML::String::TT::Directive' ), STASH => Template::Stash->new, - @_ + FILTERS => { no_escape => sub { + $_[0]->$_isa('HTML::String::Value') + ? HTML::String::Value->new(map $_->[0], @{$_[0]->{parts}}) + : HTML::String::Value->new($_) + } }, + (ref($_[0]) eq 'HASH' ? %{$_[0]} : @_) ); } 1; + +__END__ + +=head1 NAME + +HTML::String::TT - HTML string auto-escaping for L