1 package HTML::String::TT::Directive;
4 use HTML::String::Overload ();
6 use base qw(Template::Directive);
10 s/sub {/sub { package HTML::String::TT::_TMPL; use HTML::String::Overload { ignore => { q{Template::Provider} => 1, q{Template::Directive} => 1, q{Template::Document} => 1, q{Template::Plugins} => 1 } };/;
11 } Template::Directive::pad(shift->SUPER::template(@_), 2);
14 # TT code does &text(), no idea why
17 my ($self, $text) = @_;
18 return $Template::Directive::OUTPUT.' '.$self->text($text).';';
21 # https://rt.perl.org/rt3/Ticket/Display.html?id=49594
24 my ($class, $text) = @_;
26 s/(["\$\@\\])/"."\\$1"."/g;
29 return '"' . $text . '"';
38 HTML::String::TT::Directive - L<Template::Directive> overrides to forcibly escape HTML strings
42 This is not user serviceable, and is documented only for your edification.
44 Please use L<HTML::String::TT> as this module could change, be renamed, or
45 if I figure out a better way of implementing the functionality disappear
46 entirely at any moment.
52 We override this top-level method in order to pretend two things to the
53 perl subroutine definition that TT has generated - firstly,
55 package HTML::String::TT::_TMPL;
57 to ensure that no packages marked to be ignored are the current one when
58 the template code is executed. Secondly,
60 use HTML::String::Overload { ignore => { ... } };
62 where the C<...> contains a list of TT internal packages to ignore so that
63 things actually work. This list is not duplicated here since it may also
64 change without warning.
66 Additionally, the hashref option to L<HTML::String::Overload> is not
67 documented there since I'm not yet convinced that's a public API either.
71 Due to a perl bug (L<https://rt.perl.org/rt3/Ticket/Display.html?id=49594>)
72 we overload this method to change
80 since any string containing a backslash escape doesn't get marked as HTML.
81 Since we don't want to escape things that backslash escapes are normally
82 used for, this isn't really a problem for us.
86 For no reason I can comprehend at all, L<Template::Directive>'s C<textblock>
87 method calls C<&text> instead of using a method call so we have to override
92 See L<HTML::String> for authors.
94 =head1 COPYRIGHT AND LICENSE
96 See L<HTML::String> for the copyright and license.