File Coverage

blib/lib/Email/MIME/Kit/Renderer/TT.pm
Criterion Covered Total %
statement 11 11 100.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 3 3 100.0
pod 0 1 0.0
total 16 19 84.2


line stmt bran cond sub pod time code
1             package Email::MIME::Kit::Renderer::TT 1.003;
2 1     1   68733 use Moose;
  1         3  
  1         6  
3             with 'Email::MIME::Kit::Role::Renderer';
4             # ABSTRACT: render parts of your mail with Template-Toolkit
5              
6 1     1   8755 use Template 2.1;
  1         17851  
  1         189  
7              
8             #pod =head1 DESCRIPTION
9             #pod
10             #pod This is a renderer plugin for L<Email::MIME::Kit>, and renders message parts
11             #pod using L<Template Toolkit 2|Template>. When specifying a renderer in
12             #pod F<manifest.json>, you might write something like this:
13             #pod
14             #pod { ..., "renderer": "TT" }
15             #pod
16             #pod Or, to supply options:
17             #pod
18             #pod {
19             #pod ...,
20             #pod "renderer": [
21             #pod "TT",
22             #pod { ...params go here... }
23             #pod ]
24             #pod }
25             #pod
26             #pod There are only three parameters that can be supplied right now:
27             #pod
28             #pod C<strict> sets the C<STRICT> Template parameter. It defaults to 1.
29             #pod
30             #pod C<eval_perl> sets the C<EVAL_PERL> Template parameter. It defaults to 0.
31             #pod
32             #pod C<template_parameters> can be a hashref of any parameters to be passed to the
33             #pod Template constructor. Setting C<STRICT> or C<EVAL_PERL> here overrides the
34             #pod C<strict> and C<eval_perl> options.
35             #pod
36             #pod =cut
37              
38             # XXX: _include_path or something
39             # XXX: we can maybe default to the kit dir if the KitReader is Dir
40              
41             sub render {
42 6     6 0 74825 my ($self, $input_ref, $stash) = @_;
43 6   50     16 $stash ||= {};
44              
45 6         10 my $output;
46 6 50       152 $self->_tt->process($input_ref, $stash, \$output)
47             or die $self->_tt->error;
48              
49 6         29950 return \$output;
50             }
51              
52             has eval_perl => (
53             is => 'ro',
54             isa => 'Bool',
55             default => 0,
56             );
57              
58             has strict => (
59             is => 'ro',
60             isa => 'Bool',
61             default => 1,
62             );
63              
64             has template_parameters => (
65             is => 'ro',
66             isa => 'HashRef',
67             default => sub { {} },
68             );
69              
70             has _tt => (
71             is => 'ro',
72             isa => 'Template',
73             lazy => 1,
74             init_arg => undef,
75             default => sub {
76             my ($self) = @_;
77             Template->new({
78             ABSOLUTE => 0,
79             RELATIVE => 0,
80             STRICT => $self->strict,
81             EVAL_PERL => $self->eval_perl,
82             %{ $self->template_parameters },
83             });
84             },
85             );
86              
87             1;
88              
89             __END__
90              
91             =pod
92              
93             =encoding UTF-8
94              
95             =head1 NAME
96              
97             Email::MIME::Kit::Renderer::TT - render parts of your mail with Template-Toolkit
98              
99             =head1 VERSION
100              
101             version 1.003
102              
103             =head1 DESCRIPTION
104              
105             This is a renderer plugin for L<Email::MIME::Kit>, and renders message parts
106             using L<Template Toolkit 2|Template>. When specifying a renderer in
107             F<manifest.json>, you might write something like this:
108              
109             { ..., "renderer": "TT" }
110              
111             Or, to supply options:
112              
113             {
114             ...,
115             "renderer": [
116             "TT",
117             { ...params go here... }
118             ]
119             }
120              
121             There are only three parameters that can be supplied right now:
122              
123             C<strict> sets the C<STRICT> Template parameter. It defaults to 1.
124              
125             C<eval_perl> sets the C<EVAL_PERL> Template parameter. It defaults to 0.
126              
127             C<template_parameters> can be a hashref of any parameters to be passed to the
128             Template constructor. Setting C<STRICT> or C<EVAL_PERL> here overrides the
129             C<strict> and C<eval_perl> options.
130              
131             =head1 PERL VERSION
132              
133             This module should work on any version of perl still receiving updates from
134             the Perl 5 Porters. This means it should work on any version of perl released
135             in the last two to three years. (That is, if the most recently released
136             version is v5.40, then this module should work on both v5.40 and v5.38.)
137              
138             Although it may work on older versions of perl, no guarantee is made that the
139             minimum required version will not be increased. The version may be increased
140             for any reason, and there is no promise that patches will be accepted to lower
141             the minimum required perl.
142              
143             =head1 AUTHOR
144              
145             Ricardo SIGNES <cpan@semiotic.systems>
146              
147             =head1 CONTRIBUTOR
148              
149             =for stopwords Ricardo Signes
150              
151             Ricardo Signes <rjbs@semiotic.systems>
152              
153             =head1 COPYRIGHT AND LICENSE
154              
155             This software is copyright (c) 2022 by Ricardo SIGNES.
156              
157             This is free software; you can redistribute it and/or modify it under
158             the same terms as the Perl 5 programming language system itself.
159              
160             =cut