blib/lib/Dancer/Plugin/Email.pm

filter: Statementstmt 33.3% 25 / 75 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 87.5% 7 / 8 Podpod n/a totaltotal 20.9% 32 / 153 CC 28 SCAR 64.8
CC
28
Cov
19%
__ANON__
812.0
BEGIN
1.0
BEGIN
1.0
CRAP 649.8
↑ Summary
1 package Dancer::Plugin::Email;
2  
3 1 our $VERSION = '1.0400'; # VERSION
4  
5 1 ▶use Dancer qw(:syntax debug warning);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Dancer::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Email::Sender::Simple 'sendmail';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Email::Date::Format 'email_date';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use MIME::Entity;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Module::Load 'load';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶register email => sub {
Subroutine __ANON__: not called CC=28 SCAR=67.0
14 0 ▶ my $params = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
15 0 my $multipart = delete $params->{multipart};
16 0 ▶ my $extra_headers = delete($params->{headers}) || {};
Condition0%0/2
delete $params->{'headers'} || {}
l!l
00
MC/DC0%0/1
delete $params->{'headers'} || {}
delete $params->{'headers'}
Truth table0%0/2
A
A= delete $params->{'headers'}
Aresult
11
00
17 0 my $conf = plugin_setting;
18 0 ▶ my $conf_headers = $conf->{headers} || {};
Condition0%0/2
$conf->{'headers'} || {}
l!l
00
MC/DC0%0/1
$conf->{'headers'} || {}
$conf->{'headers'}
Truth table0%0/2
A
A= $conf->{'headers'}
Aresult
11
00
19 0 my %headers = ( %$conf_headers, %$params, %$extra_headers );
20 0 my $attach = $headers{attach};
21 0 my $sender = delete $headers{sender};
22 0 ▶ if (my $type = $headers{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $headers{"type"}) 0 0 0
23 0 ▶ $headers{Type} = $type eq 'html' ? 'text/html' : 'text/plain';
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'html' ? : 0 0 0
24 }
25 0 ▶ $headers{Type} ||= 'text/plain';
Condition0%0/2
$headers{"Type"} ||= "text/plain"
l!l
00
MC/DC0%0/1
$headers{"Type"} ||= "text/plain"
$headers{"Type"}
Truth table0%0/2
A
A= $headers{"Type"}
Aresult
11
00
26 0 ▶ $headers{Format} ||= 'flowed' if $headers{Type} eq 'text/plain';
Branch: 1 branch
BranchTrueFalseTotal
if $headers{"Type"} eq "text/plain" 0 0 0
Condition0%0/2
$headers{"Format"} ||= "flowed"
l!l
00
MC/DC0%0/1
$headers{"Format"} ||= "flowed"
$headers{"Format"}
Truth table0%0/2
A
A= $headers{"Format"}
Aresult
11
00
27 0 ▶ $headers{Date} ||= email_date();
Condition0%0/3
$headers{"Date"} ||= email_date()
l!l&&r!l&&!r
000
MC/DC0%0/2
$headers{"Date"} ||= email_date()
$headers{"Date"} email_date()
Truth table0%0/3
A ||= B
A= $headers{"Date"}B= email_date()
ABresult
1X1
011
000
28 0 delete $headers{$_} for qw(body message attach type);
29  
30 my $email = MIME::Entity->build(
31 Charset => 'utf-8',
32 Encoding => 'quoted-printable',
33 %headers,
34 Data => $params->{body} || $params->{message},
35 0 ▶ );
Condition0%0/3
$params->{'body'} || $params->{'message'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{'body'} || $params->{'message'}
$params->{'body'} $params->{'message'}
Truth table0%0/3
A || B
A= $params->{'body'}B= $params->{'message'}
ABresult
1X1
011
000
36 0 ▶ if ($attach) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attach) 0 0 0
37 0 ▶ if ($multipart) {
Branch: 1 branch
BranchTrueFalseTotal
if ($multipart) 0 0 0
38 # by default, when you add an attachment,
39 # C<make_multipart> will be called by MIME::Entity, but
40 # defaults to 'mixed'. Thunderbird doesn't like this for
41 # embedded images, so we have a chance to set it to
42 # 'related' or anything that the user wants
43 0 $email->make_multipart($multipart);
44 }
45 0 ▶ my @attachments = ref($attach) eq 'ARRAY' ? @$attach : $attach;
Branch: 1 branch
BranchTrueFalseTotal
ref $attach eq 'ARRAY' ? : 0 0 0
46 0 for my $attachment (@attachments) {
47 0 my %mime;
48 0 ▶ if (ref($attachment) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attachment eq 'HASH') { } 0 0 0
49 0 %mime = %$attachment;
50 0 ▶ unless ($mime{Path} || $mime{Data}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mime{"Path"} or $mime{"Data"}) 0 0 0
Condition0%0/3
$mime{"Path"} or $mime{"Data"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$mime{"Path"} or $mime{"Data"}
$mime{"Path"} $mime{"Data"}
Truth table0%0/3
A or B
A= $mime{"Path"}B= $mime{"Data"}
ABresult
1X1
011
000
51 0 warning "No Path or Data provided for this attachment!";
52 0 next;
53 };
54 0 ▶ if ($mime{Path}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mime{"Path"}) 0 0 0
55 0 ▶ $mime{Encoding} ||= 'base64';
Condition0%0/2
$mime{"Encoding"} ||= "base64"
l!l
00
MC/DC0%0/1
$mime{"Encoding"} ||= "base64"
$mime{"Encoding"}
Truth table0%0/2
A
A= $mime{"Encoding"}
Aresult
11
00
56 0 ▶ $mime{Type} ||= File::Type->mime_type($mime{Path});
Condition0%0/3
$mime{"Type"} ||= "File::Type"->mime_type($mime{"Path"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$mime{"Type"} ||= "File::Type"->mime_type($mime{"Path"})
$mime{"Type"} "File::Type"->mime_type($mime{"Path"})
Truth table0%0/3
A ||= B
A= $mime{"Type"}B= "File::Type"->mime_type($mime{"Path"})
ABresult
1X1
011
000
57 }
58 } else {
59 0 %mime = (
60 Path => $attachment,
61 Type => File::Type->mime_type($attachment),
62 Encoding => 'base64',
63 );
64 }
65 0 $email->attach(%mime);
66 }
67 }
68  
69 0 my $transport;
70 0 ▶ my $conf_transport = $conf->{transport} || {};
Condition0%0/2
$conf->{'transport'} || {}
l!l
00
MC/DC0%0/1
$conf->{'transport'} || {}
$conf->{'transport'}
Truth table0%0/2
A
A= $conf->{'transport'}
Aresult
11
00
71 0 ▶ if (my ($transport_name) = keys %$conf_transport) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($transport_name) = keys %$conf_transport) 0 0 0
72 0 ▶ my $transport_params = $conf_transport->{$transport_name} || {};
Condition0%0/2
$conf_transport->{$transport_name} || {}
l!l
00
MC/DC0%0/1
$conf_transport->{$transport_name} || {}
$conf_transport->{$transport_name}
Truth table0%0/2
A
A= $conf_transport->{$transport_name}
Aresult
11
00
73 0 my $transport_class = "Email::Sender::Transport::$transport_name";
74 0 my $transport_redirect = $transport_params->{redirect_address};
75 0 load $transport_class;
76 0 $transport = $transport_class->new($transport_params);
77  
78 0 ▶ if ($transport_redirect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transport_redirect) 0 0 0
79 0 $transport_class = 'Email::Sender::Transport::Redirect';
80 0 load $transport_class;
81 0 debug "Redirecting email to $transport_redirect.";
82 0 $transport = $transport_class->new(
83 transport => $transport,
84 redirect_address => $transport_redirect
85 );
86 }
87 }
88 0 my %sendmail_arg = ( transport => $transport );
89 0 ▶ $sendmail_arg{from} = $sender if defined $sender;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sender 0 0 0
90 0 ▶ if ( $headers{bcc} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headers{"bcc"}) 0 0 0
91 0 sendmail $email, { %sendmail_arg, to => $headers{bcc} };
92 0 $email->head->delete('bcc');
93 }
94 0 return sendmail $email, \%sendmail_arg;
95 1 };
96  
97  
98 1 register_plugin;
99  
100 # ABSTRACT: Simple email sending for Dancer applications
101  
102  
103 1 1;
104  
105 __END__
↑ Summary