| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Email::MIME::Kit::Renderer::MicroMason; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Render parts of your mail with Text::MicroMason |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1148
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with 'Email::MIME::Kit::Role::Renderer'; |
|
7
|
|
|
|
|
|
|
use Scalar::Util (); |
|
8
|
|
|
|
|
|
|
use Text::MicroMason; |
|
9
|
|
|
|
|
|
|
use Carp; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.21'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub render { |
|
14
|
|
|
|
|
|
|
my ( $self, $content_ref, $stash ) = @_; |
|
15
|
|
|
|
|
|
|
$stash ||= {}; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Parse the template with Text::MicroMason |
|
18
|
|
|
|
|
|
|
my $outbuf = $self->mason->execute( text => $$content_ref, %$stash ); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
return \$outbuf; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has mason => ( |
|
24
|
|
|
|
|
|
|
is => 'ro', |
|
25
|
|
|
|
|
|
|
## isa => 'Text::MicroMason', # T:MM isa strange subclass |
|
26
|
|
|
|
|
|
|
lazy => 1, |
|
27
|
|
|
|
|
|
|
init_arg => undef, |
|
28
|
|
|
|
|
|
|
default => sub { |
|
29
|
|
|
|
|
|
|
my ($self) = @_; |
|
30
|
|
|
|
|
|
|
my $mason = Text::MicroMason->new('-Filters', '-MKit'); |
|
31
|
|
|
|
|
|
|
$mason->{__mkit_renderer} = $self; |
|
32
|
|
|
|
|
|
|
Scalar::Util::weaken($mason->{__mkit_renderer}); |
|
33
|
|
|
|
|
|
|
return $mason; |
|
34
|
|
|
|
|
|
|
}, |
|
35
|
|
|
|
|
|
|
); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
{ |
|
38
|
|
|
|
|
|
|
$INC{'Text/MicroMason/MKit.pm'} = 1; |
|
39
|
|
|
|
|
|
|
package Text::MicroMason::MKit; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub read_file { |
|
42
|
|
|
|
|
|
|
my ($self, $file) = @_; |
|
43
|
|
|
|
|
|
|
my $text = $self->{__mkit_renderer}->kit->get_kit_entry($file); |
|
44
|
|
|
|
|
|
|
return $$text; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
no Moose; |
|
49
|
|
|
|
|
|
|
1; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=pod |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Email::MIME::Kit::Renderer::MicroMason - Render parts of your mail with Text::MicroMason |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 VERSION |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
version 1.21 |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
To use MicroMason in your mkit use something like: |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
{ |
|
68
|
|
|
|
|
|
|
"renderer": "MicroMason", |
|
69
|
|
|
|
|
|
|
"header": [ |
|
70
|
|
|
|
|
|
|
{ "From": "WY Corp <noreplies@wy.example.com" }, |
|
71
|
|
|
|
|
|
|
{ "To": "<% $ARGS{recruit}->email %>" }, |
|
72
|
|
|
|
|
|
|
{ "Subject": "Welcome aboard, <% ARGS{recruit}->name %>" } |
|
73
|
|
|
|
|
|
|
], |
|
74
|
|
|
|
|
|
|
"alternatives": [ |
|
75
|
|
|
|
|
|
|
{ "type": "text/plain", "path": "body.txt" }, |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
|
|
|
|
|
|
"type": "text/html", |
|
78
|
|
|
|
|
|
|
"path": "body.html", |
|
79
|
|
|
|
|
|
|
"container_type": "multipart/related", |
|
80
|
|
|
|
|
|
|
"attachments": [ { "type": "image/jpeg", "path": "logo.jpg" } ] |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
] |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Then in your email templates (body.txt and body.html) you can do: |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
<%args> |
|
88
|
|
|
|
|
|
|
$recruit |
|
89
|
|
|
|
|
|
|
$cid_for |
|
90
|
|
|
|
|
|
|
</%args> |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
<& "../includes/header.msn", %ARGS &> |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
<p> |
|
95
|
|
|
|
|
|
|
Dear <% $recruit->name %>, |
|
96
|
|
|
|
|
|
|
</p> |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
<p> |
|
99
|
|
|
|
|
|
|
Welcome to WY Corp. |
|
100
|
|
|
|
|
|
|
</p> |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
<& "../includes/footer.msn", %ARGS &> |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
EMK::Renderer::MicroMason will try to make any components included with |
|
105
|
|
|
|
|
|
|
<& ... &> relative to the mkit directory. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This renderer for L<Email::MIME::Kit> uses L<Text::MicroMason> to enable |
|
110
|
|
|
|
|
|
|
you to write your mkits using basic Mason syntax. See |
|
111
|
|
|
|
|
|
|
L<Text::MicroMason::HTMLMason> for details on the syntax. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This is based on L<Text::MicroMason> rather than the full blown L<HTML::Mason> |
|
114
|
|
|
|
|
|
|
because L<HTML::Mason> is focused on directories and files and |
|
115
|
|
|
|
|
|
|
L<Email::MIME::Kit> prefers to work with strings. L<Text::MicroMason> |
|
116
|
|
|
|
|
|
|
accommodates this and is a bit smaller than it's big brother. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 METHODS |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=over 4 |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item render() |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
render( $content_ref, $stash ) |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Called by L<Email::MIME::Kit::Renderer> to parse template strings |
|
127
|
|
|
|
|
|
|
($content_ref) with L<Text::MicroMason> and return a plain text string. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=back |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 ACKNOWLEGEMENTS |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This is basically just Ricardo SIGNES' EMK::Renderer::TestRenderer with |
|
134
|
|
|
|
|
|
|
basic integration of L<Text::MicroMason>. Thanks to Ricardo for the |
|
135
|
|
|
|
|
|
|
excellent EMK package. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
L<Email::MIME::Kit>, L<HTML::Mason>, L<Text::MicroMason>, |
|
140
|
|
|
|
|
|
|
and L<Text::MicroMason::HTMLMason>. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Mark Grimes, E<lt>mgrimes@cpan.orgE<gt> |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Mark Grimes, E<lt>mgrimes@cpan.orgE<gt>. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
151
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |