Bulk/Command.pm

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