770f5fad63dc21fc7bce2b60441e94d5e200dac9
[scpubgit/HTML-String.git] / lib / HTML / String / TT / Directive.pm
1 package HTML::String::TT::Directive;
2
3 use strictures 1;
4 use HTML::String::Overload ();
5 use Data::Munge;
6 use base qw(Template::Directive);
7
8 sub template {
9     return byval {
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);
12 }
13
14 # TT code does &text(), no idea why
15
16 sub textblock {
17     my ($self, $text) = @_;
18     return $Template::Directive::OUTPUT.' '.$self->text($text).';';
19 }
20
21 # https://rt.perl.org/rt3/Ticket/Display.html?id=49594
22
23 sub text {
24     my ($class, $text) = @_;
25     for ($text) {
26         s/(["\$\@\\])/"."\\$1"."/g;
27         s/\n/"."\\n"."/g;
28     }
29     return '"' . $text . '"';
30 }
31
32 1;