File Coverage

blib/lib/Email/MIME/Kit/Bulk/Command.pm
Criterion Covered Total %
statement 36 36 100.0
branch 4 6 66.6
condition n/a
subroutine 10 10 100.0
pod 0 2 0.0
total 50 54 92.5


line stmt bran cond sub pod time code
1             package Email::MIME::Kit::Bulk::Command;
2             our $AUTHORITY = 'cpan:YANICK';
3             # ABSTRACT: send bulk emails using Email::MIME::Kit
4             $Email::MIME::Kit::Bulk::Command::VERSION = '0.0.3';
5              
6 10     10   501219 use strict;
  10         10  
  10         257  
7 10     10   30 use warnings;
  10         10  
  10         225  
8              
9 10     10   3918 use MooseX::App::Simple;
  10         6874324  
  10         31  
10              
11 10     10   8271541 use Email::MIME::Kit::Bulk;
  10         51  
  10         630  
12 10     10   67 use Email::MIME::Kit::Bulk::Target;
  10         19  
  10         164  
13 10     10   33 use JSON;
  10         19  
  10         91  
14 10     10   1287 use MooseX::Types::Path::Tiny qw/ Path /;
  10         11  
  10         114  
15 10     10   19385 use PerlX::Maybe;
  10         12  
  10         4220  
16              
17             option kit => (
18             is => 'ro',
19             isa => Path,
20             required => 1,
21             coerce => 1,
22             documentation => 'path to the mime kit directory',
23             );
24              
25             option from => (
26             is => 'ro',
27             isa => 'Str',
28             documentation => 'sender address',
29             required => 1,
30             );
31              
32             option processes => (
33             is => 'ro',
34             isa => 'Maybe[Int]',
35             documentation => 'nbr of parallel processes for sending emails',
36             );
37              
38             option quiet => (
39             is => 'ro',
40             isa => 'Bool',
41             documentation => q{don't output anything},
42             default => 0,
43             );
44              
45             has transport => (
46             is => 'ro',
47             );
48              
49             has _targets_file => (
50             is => 'ro',
51             isa => Path,
52             lazy => 1,
53             default => sub { shift->kit->child('targets.json') },
54             );
55              
56             sub BUILD {
57 9     9 0 18 my $self = shift;
58              
59             die 'Kit directory must have a manifest'
60 18         189 unless grep { -r }
61             grep {
62 9 50       252 my $f = $_->basename;
  45         1296  
63 45 100       702 $f =~ /^manifest\./ && $f =~ /\.json$/
64             } $self->kit->children;
65              
66 9 50       432 die 'Cannot find target specification (' . $self->_targets_file . ')'
67             unless -e $self->_targets_file;
68             }
69              
70             sub run {
71 9     9 0 9 my $self = shift;
72              
73 9         9 my @addresses = @{ decode_json($self->_targets_file->slurp) };
  9         225  
74              
75             my $mailer = Email::MIME::Kit::Bulk->new(
76             verbose => !$self->quiet,
77 9         1863 targets => [ map { Email::MIME::Kit::Bulk::Target->new($_) } @addresses ],
  18         495  
78             kit => $self->kit,
79             maybe from => $self->from,
80             maybe processes => $self->processes,
81             maybe transport => $self->transport,
82             );
83              
84 9         45 $mailer->send;
85             }
86              
87             __PACKAGE__->meta->make_immutable;
88              
89             1;
90              
91             __END__
92              
93             =pod
94              
95             =encoding UTF-8
96              
97             =head1 NAME
98              
99             Email::MIME::Kit::Bulk::Command - send bulk emails using Email::MIME::Kit
100              
101             =head1 VERSION
102              
103             version 0.0.3
104              
105             =head1 SYNOPSIS
106              
107             use Email::MIME::Kit::Bulk::Command;
108              
109             Email::MIME::Kit::Bulk::Command->new_with_options->run;
110              
111             =head1 AUTHORS
112              
113             =over 4
114              
115             =item *
116              
117             Jesse Luehrs <doy@cpan.org>
118              
119             =item *
120              
121             Yanick Champoux <yanick.champoux@iinteractive.com>
122              
123             =back
124              
125             =head1 COPYRIGHT AND LICENSE
126              
127             This software is copyright (c) 2017 by Infinity Interactive <contact@iinteractive.com>.
128              
129             This is free software; you can redistribute it and/or modify it under
130             the same terms as the Perl 5 programming language system itself.
131              
132             =cut