blib/lib/Email/MIME/Kit/Renderer/Text/Template.pm

filter: Statementstmt 100% 26 / 26 Branchbran 70.0% 7 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 82.9% 39 / 47 CC 7 SCAR 11.9
CC
7
Cov
87%
_enref_as_needed
4.2
render
4.0
BEGIN
1.0
CRAP 3.3
↑ Summary
1 package Email::MIME::Kit::Renderer::Text::Template 1.101303;
2 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 with 'Email::MIME::Kit::Role::Renderer';
4 # ABSTRACT: render parts of your mail with Text::Template
5  
6 1 ▶use Module::Runtime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub _enref_as_needed {
9 8 ▶ my ($self, $hash) = @_;
Subroutine _enref_as_needed: called CC=4 SCAR=14.5
10  
11 8 my %return;
12 8 ▶ while (my ($k, $v) = each %$hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$hash) 21 8 29
13 21 ▶ $return{ $k } = (ref $v and not blessed $v) ? $v : \$v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v && !builtin::blessed($v) ? : 21 0 21
Condition33%1/3
ref $v and not builtin::blessed($v)
!ll&&!rl&&r
0021
MC/DC0%0/2
ref $v and not builtin::blessed($v)
ref $v not builtin::blessed($v)
Truth table33%1/3
A and not(B)
A= ref $vB= not builtin::blessed($v)
ABresult
0X0
100
111
14 }
15  
16 8 return \%return;
17 }
18  
19 #pod =attr template_class
20 #pod
21 #pod This attribute stores the name of the class that will be standing in for
22 #pod Text::Template, if any. It defaults, obviously, to Text::Template.
23 #pod
24 #pod =cut
25  
26 1 has template_class => (
27 is => 'ro',
28 isa => 'Str',
29 default => 'Text::Template',
30 );
31  
32 #pod =attr template_args
33 #pod
34 #pod These are the arguments that will be passed to C<fill_this_in> along with the
35 #pod template, input, and a few required handlers.
36 #pod
37 #pod =cut
38  
39 1 has template_args => (
40 is => 'ro',
41 isa => 'HashRef',
42 );
43  
44 sub render {
45 8 ▶ my ($self, $input_ref, $args)= @_;
Subroutine render: called CC=4 SCAR=13.9
Pod undocumented
46  
47 my $hash = $self->_enref_as_needed({
48 8 ▶ (map {; $_ => ref $args->{$_} ? $args->{$_} : \$args->{$_} } keys %$args),
Branch: 1 branch
BranchTrueFalseTotal
ref $args->{$_} ? : 4 17 21
49 });
50  
51 8 my $template_class = $self->template_class;
52 8 Module::Runtime::require_module($template_class);
53  
54 my $result = $template_class->fill_this_in(
55 $$input_ref,
56 8 ▶ %{ $self->{template_args} || {} },
Branch: 1 branch
BranchTrueFalseTotal
$self->{"template_args"} or {} 8 0 8
57 HASH => $hash,
58 2 ▶ BROKEN => sub { my %hash = @_; die $hash{error}; },
Subroutine __ANON__: called CC=1 SCAR=0.0
59 8 );
60  
61 # :-( -- rjbs, 2012-10-01
62 6 ▶ die $Text::Template::ERROR unless defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 6 6
63  
64 6 return \$result;
65 }
66  
67 1 1;
68  
69 __END__
70  
71 =pod
72  
73 =encoding UTF-8
74  
75 =head1 NAME
76  
77 Email::MIME::Kit::Renderer::Text::Template - render parts of your mail with Text::Template
78  
79 =head1 VERSION
80  
81 version 1.101303
82  
83 =head1 PERL VERSION
84  
85 This module should work on any version of perl still receiving updates from
86 the Perl 5 Porters. This means it should work on any version of perl released
87 in the last two to three years. (That is, if the most recently released
88 version is v5.40, then this module should work on both v5.40 and v5.38.)
89  
90 Although it may work on older versions of perl, no guarantee is made that the
91 minimum required version will not be increased. The version may be increased
92 for any reason, and there is no promise that patches will be accepted to lower
93 the minimum required perl.
94  
95 =head1 ATTRIBUTES
96  
97 =head2 template_class
98  
99 This attribute stores the name of the class that will be standing in for
100 Text::Template, if any. It defaults, obviously, to Text::Template.
101  
102 =head2 template_args
103  
104 These are the arguments that will be passed to C<fill_this_in> along with the
105 template, input, and a few required handlers.
106  
107 =head1 AUTHOR
108  
109 Ricardo Signes <rjbs@semiotic.systems>
110  
111 =head1 COPYRIGHT AND LICENSE
112  
113 This software is copyright (c) 2022 by Ricardo Signes.
114  
115 This is free software; you can redistribute it and/or modify it under
116 the same terms as the Perl 5 programming language system itself.
117  
118 =cut
↑ Summary