File Coverage

blib/lib/Email/MIME/Kit/Bulk/Target.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 24 24 100.0


line stmt bran cond sub pod time code
1             package Email::MIME::Kit::Bulk::Target;
2             our $AUTHORITY = 'cpan:YANICK';
3             # ABSTRACT: Destination for an Email::MIME::Kit::Bulk email
4             $Email::MIME::Kit::Bulk::Target::VERSION = '0.0.3';
5              
6 10     10   40 use strict;
  10         10  
  10         273  
7 10     10   30 use warnings;
  10         10  
  10         219  
8              
9 10     10   21 use Moose;
  10         28  
  10         52  
10 10     10   39953 use namespace::autoclean;
  10         10  
  10         90  
11              
12 10     10   654 use MooseX::Types::Email;
  10         10  
  10         101  
13              
14              
15             has to => (
16             is => 'ro',
17             isa => 'MooseX::Types::Email::EmailAddress',
18             required => 1,
19             );
20              
21              
22             has cc => (
23             traits => ['Array'],
24             isa => 'ArrayRef[MooseX::Types::Email::EmailAddress]',
25             default => sub { [] },
26             handles => {
27             cc => 'elements',
28             },
29             );
30              
31              
32             has bcc => (
33             traits => ['Array'],
34             isa => 'ArrayRef[MooseX::Types::Email::EmailAddress]',
35             default => sub { [] },
36             handles => {
37             bcc => 'elements',
38             },
39             );
40              
41              
42             has from => (
43             is => 'ro',
44             isa => 'MooseX::Types::Email::EmailAddress',
45             );
46              
47              
48             has language => (
49             is => 'ro',
50             isa => 'Str',
51             predicate => 'has_language',
52             );
53              
54              
55             has template_params => (
56             is => 'ro',
57             isa => 'HashRef',
58             default => sub { {} },
59             );
60              
61              
62             has extra_attachments => (
63             traits => ['Array'],
64             isa => 'ArrayRef[Str|ArrayRef[Str]]',
65             default => sub { [] },
66             handles => {
67             extra_attachments => 'elements',
68             },
69             );
70              
71              
72             sub recipients {
73 2     2 1 4 my $self = shift;
74              
75             # TODO remove dupes?
76             return (
77 2         50 $self->to,
78             $self->cc,
79             $self->bcc,
80             );
81             }
82              
83             __PACKAGE__->meta->make_immutable;
84              
85             1;
86              
87             __END__
88              
89             =pod
90              
91             =encoding UTF-8
92              
93             =head1 NAME
94              
95             Email::MIME::Kit::Bulk::Target - Destination for an Email::MIME::Kit::Bulk email
96              
97             =head1 VERSION
98              
99             version 0.0.3
100              
101             =head1 SYNOPSIS
102              
103             use Email::MIME::Kit::Bulk::Target;
104              
105             my $target = Email::MIME::Kit::Bulk::Target->new(
106             to => 'someone@somewhere.com',
107             cc => [ 'someone_else@somewhere.com' ],
108             bcc => [ 'sneaky@somewhere.com' ],
109             from => 'me@somewhere.com',
110             language => 'en',
111             template_params => {
112             greetings => 'Hi',
113             },
114             extra_attachments => [ 'foo.pdf' ]
115             );
116            
117             Email::MIME::Kit::Bulk->new(
118             kit => '/path/to/mime/kit',
119             processes => 5,
120             targets => [ $target ],
121             )->send;
122              
123             =head1 DESCRIPTION
124              
125             A L<Email::MIME::Kit::Bulk> object will produce one email for every
126             C<Email::MIME::Kit::Bulk::Target> object it is given. Each target object
127             defines the recipients of the email, and can also be take
128             attachments, specific I<From> address and custom parameters for the MIME kit
129             template.
130              
131             =head1 METHODS
132              
133             =head2 new( %args )
134              
135             Constructor.
136              
137             =head3 Arguments
138              
139             =over
140              
141             =item to => $email_address
142              
143             C<To> Email address. Can be a string or a L<MooseX::Types::Email::EmailAddress> object.
144              
145             Required.
146              
147             =item cc => \@email_addresses
148              
149             C<Cc> Email addressses. Array ref of L<MooseX::Types::Email::EmailAddress> objects.
150              
151             =item bcc => \@email_addresses
152              
153             C<Bcc> Email addressses. Array ref of L<MooseX::Types::Email::EmailAddress> objects.
154              
155             =item from => $email_address
156              
157             Address to use for the C<From> originator.
158             Must be a L<MooseX::Types::Email::EmailAddress> object.
159              
160             =item language => $lang
161              
162             Language to use for this target.
163              
164             =item template_params => \%params
165              
166             Parameters to be passed to the L<Email::MIME::Kit> template.
167              
168             =item extra_attachments => \@attachments
169              
170             Attachments to add to the email for this target.
171              
172             =back
173              
174             =head2 to()
175              
176             Returns the L<MooseX::Types::Email::EmailAddress> object
177             for the C<To> recipient.
178              
179             =head2 cc()
180              
181             my @cc = $target->cc;
182              
183             Returns the list of L<MooseX::Types::Email::EmailAddress> objects
184             for the C<Cc> recipients.
185              
186             =head2 bcc()
187              
188             my @bcc = $target->bcc;
189              
190             Returns the list of L<MooseX::Types::Email::EmailAddress> objects
191             for the C<Bcc> recipients.
192              
193             =head2 from()
194              
195             my $from = $target->from;
196              
197             Returns the L<MooseX::Types::Email::EmailAddress> object
198             for the C<From> originator.
199              
200             =head2 language()
201              
202             my $lang = $target->language;
203              
204             Returns the language set for the target.
205              
206             =head2 has_language()
207              
208             Returns true if a language was set for the target.
209              
210             =head2 template_params()
211              
212             Returns the hash ref of the parameters that will be passed to the
213             L<Email::MIME::Kit> template.
214              
215             =head2 extra_attachments()
216              
217             Returns the list of extra attachments that will be added
218             to the email for this target.
219              
220             =head2 recipients
221              
222             Returns all the recipients (I<To>, I<Cc> and I<Bcc> combined) of the email.
223              
224             =head1 AUTHORS
225              
226             =over 4
227              
228             =item *
229              
230             Jesse Luehrs <doy@cpan.org>
231              
232             =item *
233              
234             Yanick Champoux <yanick.champoux@iinteractive.com>
235              
236             =back
237              
238             =head1 COPYRIGHT AND LICENSE
239              
240             This software is copyright (c) 2017 by Infinity Interactive <contact@iinteractive.com>.
241              
242             This is free software; you can redistribute it and/or modify it under
243             the same terms as the Perl 5 programming language system itself.
244              
245             =cut