From: Matt S Trout Date: Sat, 11 Aug 2012 17:08:14 +0000 (+0000) Subject: TT support X-Git-Tag: v1.000000~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ed99cbb44b0589b147076f6874c331818db44b83;p=scpubgit%2FHTML-String.git TT support --- diff --git a/lib/HTML/String/Overload.pm b/lib/HTML/String/Overload.pm index e5f7c72..1191c4a 100644 --- a/lib/HTML/String/Overload.pm +++ b/lib/HTML/String/Overload.pm @@ -3,13 +3,15 @@ package HTML::String::Overload; use strictures 1; use HTML::String; use B::Hooks::EndOfScope; -use overload ''; +use overload (); sub import { - overload::constant q => \&html; - on_scope_end { + overload::constant q => \&html; + on_scope_end { __PACKAGE__->unimport }; +} + +sub unimport { overload::remove_constant('q'); - } } 1; diff --git a/lib/HTML/String/TT.pm b/lib/HTML/String/TT.pm new file mode 100644 index 0000000..fb1f1cb --- /dev/null +++ b/lib/HTML/String/TT.pm @@ -0,0 +1,20 @@ +package HTML::String::TT; + +use strictures 1; +use Template; +use Template::Parser; +use Template::Stash; +use HTML::String::TT::Directive; + +sub new { + shift; + Template->new( + PARSER => Template::Parser->new( + FACTORY => 'HTML::String::TT::Directive' + ), + STASH => Template::Stash->new, + @_ + ); +} + +1; diff --git a/lib/HTML/String/TT/Directive.pm b/lib/HTML/String/TT/Directive.pm new file mode 100644 index 0000000..11fa963 --- /dev/null +++ b/lib/HTML/String/TT/Directive.pm @@ -0,0 +1,13 @@ +package HTML::String::TT::Directive; + +use strictures 1; +use HTML::String::Overload (); +use base qw(Template::Directive); + +sub template { + my $result = Template::Directive::pad(shift->SUPER::template(@_), 2); + $result =~ s/sub {/sub { use HTML::String::Overload;/; + $result; +} + +1; diff --git a/lib/HTML/String/Value.pm b/lib/HTML/String/Value.pm index d03b287..d622694 100644 --- a/lib/HTML/String/Value.pm +++ b/lib/HTML/String/Value.pm @@ -23,6 +23,7 @@ use overload '""' => 'escaped_string', '.' => 'dot', '.=' => 'dot_equals', + '=' => 'clone', 'cmp' => op_factory('cmp'), 'eq' => op_factory('eq'), @@ -109,4 +110,10 @@ sub dot_equals { return $self; } +sub clone { + my $self = shift; + + return ref($self)->new(@{$self->{parts}}); +} + 1; diff --git a/t/simple.t b/t/simple.t index da35254..b77accd 100644 --- a/t/simple.t +++ b/t/simple.t @@ -11,7 +11,7 @@ is("$one", 'Hi <bob>'); my $two = do { use HTML::String::Overload; - "${hi}" + "${hi}"; }; is("$two", 'Hi <bob>');