File Coverage

blib/lib/Email/MIME/Kit/Renderer/TestRenderer.pm
Criterion Covered Total %
statement 14 14 100.0
branch 4 4 100.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 22 23 95.6


line stmt bran cond sub pod time code
1             package Email::MIME::Kit::Renderer::TestRenderer 3.000007;
2             # ABSTRACT: extremely simple renderer for testing purposes only
3              
4 4     4   74578 use v5.20.0;
  4         26  
5 4     4   578 use Moose;
  4         478045  
  4         27  
6             with 'Email::MIME::Kit::Role::Renderer';
7              
8             #pod =head1 WARNING
9             #pod
10             #pod Seriously, this is horrible code. If you want, look at it. It's swell for
11             #pod testing simple things, but if you use this for real mkits, you're going to be
12             #pod upset by something horrible soon.
13             #pod
14             #pod =head1 DESCRIPTION
15             #pod
16             #pod The test renderer is like a version of Template Toolkit 2 that has had a crayon
17             #pod shoved up its nose and into its brain. It can only do a very few things, but
18             #pod it does them well enough to test simple kits.
19             #pod
20             #pod Given the following template:
21             #pod
22             #pod This will say "I love pie": [% actor %] [% m_obj.verb() %] [% z_by("me") %]
23             #pod
24             #pod ...and the following set of variables:
25             #pod
26             #pod {
27             #pod actor => 'I',
28             #pod m_obj => $object_whose_verb_method_returns_love,
29             #pod z_by => sub { 'me' },
30             #pod }
31             #pod
32             #pod ..then it will be a true statement.
33             #pod
34             #pod In method calls, the parens are B<not> optional. Anything between them (or
35             #pod between the parens in a coderef call) is evaluated like perl code. For
36             #pod example, this will actually get the OS:
37             #pod
38             #pod [% z_by($^O) %]
39             #pod
40             #pod =cut
41              
42             sub render {
43 25     25 0 209 my ($self, $content_ref, $stash) = @_;
44              
45 25         92 my $output = $$content_ref;
46 25         206 for my $key (sort %$stash) {
47 126         2327 $output =~
48             s<\[%\s+\Q$key\E(?:(?:\.(\w+))?\((.*?)\))?\s+%\]>
49             [ defined $2
50 19 100       637 ? ($1 ? $stash->{$key}->$1(eval $2) : $stash->{$key}->(eval $2))
    100          
51             : $stash->{$key}
52             ]ge;
53             }
54 25         156  
55             return \$output;
56             }
57 4     4   29170  
  4         12  
  4         24  
58             no Moose;
59             __PACKAGE__->meta->make_immutable;
60             1;
61              
62             __END__
63              
64             =pod
65              
66             =encoding UTF-8
67              
68             =head1 NAME
69              
70             Email::MIME::Kit::Renderer::TestRenderer - extremely simple renderer for testing purposes only
71              
72             =head1 VERSION
73              
74             version 3.000007
75              
76             =head1 DESCRIPTION
77              
78             The test renderer is like a version of Template Toolkit 2 that has had a crayon
79             shoved up its nose and into its brain. It can only do a very few things, but
80             it does them well enough to test simple kits.
81              
82             Given the following template:
83              
84             This will say "I love pie": [% actor %] [% m_obj.verb() %] [% z_by("me") %]
85              
86             ...and the following set of variables:
87              
88             {
89             actor => 'I',
90             m_obj => $object_whose_verb_method_returns_love,
91             z_by => sub { 'me' },
92             }
93              
94             ..then it will be a true statement.
95              
96             In method calls, the parens are B<not> optional. Anything between them (or
97             between the parens in a coderef call) is evaluated like perl code. For
98             example, this will actually get the OS:
99              
100             [% z_by($^O) %]
101              
102             =head1 PERL VERSION
103              
104             This library should run on perls released even a long time ago. It should work
105             on any version of perl released in the last five years.
106              
107             Although it may work on older versions of perl, no guarantee is made that the
108             minimum required version will not be increased. The version may be increased
109             for any reason, and there is no promise that patches will be accepted to lower
110             the minimum required perl.
111              
112             =head1 WARNING
113              
114             Seriously, this is horrible code. If you want, look at it. It's swell for
115             testing simple things, but if you use this for real mkits, you're going to be
116             upset by something horrible soon.
117              
118             =head1 AUTHOR
119              
120             Ricardo Signes <rjbs@cpan.org>
121              
122             =head1 COPYRIGHT AND LICENSE
123              
124             This software is copyright (c) 2023 by Ricardo Signes.
125              
126             This is free software; you can redistribute it and/or modify it under
127             the same terms as the Perl 5 programming language system itself.
128              
129             =cut