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;
--- /dev/null
+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;
--- /dev/null
+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;
'""' => 'escaped_string',
'.' => 'dot',
'.=' => 'dot_equals',
+ '=' => 'clone',
'cmp' => op_factory('cmp'),
'eq' => op_factory('eq'),
return $self;
}
+sub clone {
+ my $self = shift;
+
+ return ref($self)->new(@{$self->{parts}});
+}
+
1;
my $two = do {
use HTML::String::Overload;
- "<tag>${hi}</tag>"
+ "<tag>${hi}</tag>";
};
is("$two", '<tag>Hi <bob></tag>');