| 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
| |||||||||||||||||||||||||||||
| 21 | 9 | ▶ | ref $args eq "HASH" or croak 'You must pass me a hashref to describe the email'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 8 | my $config = plugin_setting; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 8 | my $email; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 8 | ▶ | if ($args->{email}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$params->{"from"} = $args->{"envelope-from"} or $email->get_header("from")
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")
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$params->{"to"} = $args->{"envelope-to"} or $email->get_header("to")
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")
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 5 | ▶ | if (blessed $args->{transport}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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"})
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"})
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | if (my $choice = delete $transport->{class}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||