lib/Dancer/Plugin/EmailSender.pm

filter: Statementstmt 98.3% 61 / 62 Branchbran 78.5% 22 / 28 Conditioncond 88.8% 8 / 9 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 92.2% 107 / 116 CC 18 SCAR 25.1
CC
18
Cov
92%
__ANON__
18.6
BEGIN
1.0
BEGIN
1.0
CRAP 12.3
↑ Summary
1 package Dancer::Plugin::EmailSender;
2 {
3 1 $Dancer::Plugin::EmailSender::VERSION = '0.002';
4 }
5 #ABSTRACT: Easily use Email::Sender from Dancer
6  
7 1 ▶use Carp qw{croak};
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Dancer ':syntax';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Dancer::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Email::MIME;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Email::Sender::Simple qw{sendmail};
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Module::Load 'load';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Test::More import => ['!pass'];
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 10 ▶register sendemail => sub {
Subroutine __ANON__: called CC=18 SCAR=29.2
20 10 ▶ my ($args) = @_ or croak 'You must pass me information on what to send';
Branch: 1 branch
BranchTrueFalseTotal
my($args) = or croak("You must pass me information on what to send") 9 1 10
21 9 ▶ ref $args eq "HASH" or croak 'You must pass me a hashref to describe the email';
Branch: 1 branch
BranchTrueFalseTotal
ref $args eq "HASH" or croak("You must pass me a hashref to describe the email") 8 1 9
22  
23 8 my $config = plugin_setting;
24  
25 8 my $email;
26  
27 8 ▶ if ($args->{email}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'email'}) { } 1 7 8
28 1 $email = Email::Abstract->new ($args->{email});
29 } else {
30 7 ▶ my $headers = {%{ref $config->{headers} eq 'HASH' ? $config->{headers} : {}}, %{ref $args->{headers} eq 'HASH' ? $args->{headers} : {}}, From => $args->{from}, To => join ",", ref $args->{to} eq 'ARRAY' ? @{$args->{to}} : ()};
Branch: 3 branches
BranchTrueFalseTotal
ref $config->{'headers'} eq 'HASH' ? : 7 0 7
ref $args->{'headers'} eq 'HASH' ? : 1 6 7
ref $args->{'to'} eq 'ARRAY' ? : 4 3 7
31 7 $email = Email::Abstract->new (Email::MIME->create (header_str => [%{$headers}], body => $args->{body}));
32 }
33  
34 8 ▶ croak 'Could not extract or construct an email from our parameters' unless ($email);
Branch: 1 branch
BranchTrueFalseTotal
unless $email 0 8 8
35  
36 8 my $params = {};
37 8 ▶ ($params->{from} = $args->{'envelope-from'}) or $email->get_header ('from') or croak 'You must tell me who the email is from';
Branch: 1 branch
BranchTrueFalseTotal
$params->{"from"} = $args->{"envelope-from"} or $email->get_header("from") or croak("You must tell me who the email is from") 7 1 8
Condition100%3/3
$params->{"from"} = $args->{"envelope-from"} or $email->get_header("from")
l!l&&r!l&&!r
341
MC/DC100%2/2
$params->{"from"} = $args->{"envelope-from"} or $email->get_header("from")
$params->{"from"} = $args->{"envelope-from"} $email->get_header("from")
Truth table100%3/3
A or B
A= $params->{"from"} = $args->{"envelope-from"}B= $email->get_header("from")
ABresult
1X1
011
000
38 7 ▶ ($params->{to} = $args->{'envelope-to'}) or $email->get_header ('to') or croak 'You must tell me to whom to send the email';
Branch: 1 branch
BranchTrueFalseTotal
$params->{"to"} = $args->{"envelope-to"} or $email->get_header("to") or croak("You must tell me to whom to send the email") 5 2 7
Condition100%3/3
$params->{"to"} = $args->{"envelope-to"} or $email->get_header("to")
l!l&&r!l&&!r
142
MC/DC100%2/2
$params->{"to"} = $args->{"envelope-to"} or $email->get_header("to")
$params->{"to"} = $args->{"envelope-to"} $email->get_header("to")
Truth table100%3/3
A or B
A= $params->{"to"} = $args->{"envelope-to"}B= $email->get_header("to")
ABresult
1X1
011
000
39  
40 5 ▶ if (blessed $args->{transport}) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($args->{'transport'})) { } 0 5 5
elsif (not defined $args->{'transport'} and builtin::blessed($config->{'transport'})) { } 4 1 5
41 0 $params->{transport} = $args->{transport};
42 ▶ } elsif (!defined $args->{transport} and blessed $config->{transport}) {
Condition66%2/3
not defined $args->{"transport"} and builtin::blessed($config->{"transport"})
!ll&&!rl&&r
104
MC/DC50%1/2
not defined $args->{"transport"} and builtin::blessed($config->{"transport"})
not defined $args->{"transport"} builtin::blessed($config->{"transport"})
Truth table66%2/3
not(A) and B
A= not defined $args->{"transport"}B= builtin::blessed($config->{"transport"})
ABresult
0X0
100
111
43 4 $params->{transport} = $config->{transport};
44 } else {
45 1 ▶ my $transport = {%{ref $config->{transport} eq 'HASH' ? $config->{transport} : {}}, %{ref $args->{transport} eq 'HASH' ? $args->{transport} : {}}};
Branch: 2 branches
BranchTrueFalseTotal
ref $config->{'transport'} eq 'HASH' ? : 0 1 1
ref $args->{'transport'} eq 'HASH' ? : 1 0 1
46 1 ▶ if (my $choice = delete $transport->{class}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $choice = delete $transport->{"class"}) 1 0 1
47 1 my $class = "Email::Sender::Transport::$choice";
48 1 load $class;
49 1 $params->{transport} = $class->new ($transport);
50 }
51 }
52  
53 5 return sendmail $email, $params;
54 1 };
55  
56 1 register_plugin;
57  
58  
59 1 1;
60  
61 __END__
↑ Summary