| 1 | package Email::Sender::Role::CommonSending 2.603; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: the common sending tasks most Email::Sender classes will need | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Email::Abstract 3.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use Email::Sender::Success; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Email::Sender::Failure::Temporary; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use Email::Sender::Failure::Permanent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 15 | #pod | ||||||||||||||||||||||||||||
| 16 | #pod Email::Sender::Role::CommonSending provides a number of features that should | ||||||||||||||||||||||||||||
| 17 | #pod ease writing new classes that perform the L<Email::Sender> role. Instead of | ||||||||||||||||||||||||||||
| 18 | #pod writing a C<send> method, implementors will need to write a smaller | ||||||||||||||||||||||||||||
| 19 | #pod C<send_email> method, which will be passed an L<Email::Abstract> object and | ||||||||||||||||||||||||||||
| 20 | #pod envelope containing C<from> and C<to> entries. The C<to> entry will be | ||||||||||||||||||||||||||||
| 21 | #pod guaranteed to be an array reference. | ||||||||||||||||||||||||||||
| 22 | #pod | ||||||||||||||||||||||||||||
| 23 | #pod A C<success> method will also be provided as a shortcut for calling: | ||||||||||||||||||||||||||||
| 24 | #pod | ||||||||||||||||||||||||||||
| 25 | #pod Email::Sender::Success->new(...); | ||||||||||||||||||||||||||||
| 26 | #pod | ||||||||||||||||||||||||||||
| 27 | #pod A few other minor details are handled by CommonSending; for more information, | ||||||||||||||||||||||||||||
| 28 | #pod consult the source. | ||||||||||||||||||||||||||||
| 29 | #pod | ||||||||||||||||||||||||||||
| 30 | #pod The methods documented here may be overridden to alter the behavior of the | ||||||||||||||||||||||||||||
| 31 | #pod CommonSending role. | ||||||||||||||||||||||||||||
| 32 | #pod | ||||||||||||||||||||||||||||
| 33 | #pod =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 13 | with 'Email::Sender'; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 13 | requires 'send_email'; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 30 | ▶ | sub send { | ||||||||||||||||||||||||||
|
Subroutine
send: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 30 | my ($self, $message, $env, @rest) = @_; | |||||||||||||||||||||||||||
| 41 | 30 | my $email = $self->prepare_email($message); | |||||||||||||||||||||||||||
| 42 | 30 | my $envelope = $self->prepare_envelope($env); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 30 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 30 | return $self->send_email($email, $envelope, @rest); | |||||||||||||||||||||||||||
| 46 | 11 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 47 | 11 | ▶ | Carp::confess('unknown error') unless my $err = $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 11 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
&try(sub {
$err->isa("Email::Sender::Failure");
}
) and not my(@tmp) = $err->recipients
MC/DC50%1/2
&try(sub {
$err->isa("Email::Sender::Failure");
}
) and not my(@tmp) = $err->recipients
&try(sub {
$err->isa("Email::Sender::Failure");
}
)
not my(@tmp) = $err->recipients
Truth table66%2/3
A and not(B)
A= &try(sub {
$err->isa("Email::Sender::Failure");
}
)B= not my(@tmp) = $err->recipients
| |||||||||||||||||||||||||||||
| 50 | 11 | ▶ | try { $err->isa('Email::Sender::Failure') } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | and ! (my @tmp = $err->recipients) | ||||||||||||||||||||||||||||
| 52 | ) { | ||||||||||||||||||||||||||||
| 53 | 6 | $err->_set_recipients([ @{ $envelope->{to} } ]); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 11 | die $err; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 30 | } | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | #pod =method prepare_email | ||||||||||||||||||||||||||||
| 61 | #pod | ||||||||||||||||||||||||||||
| 62 | #pod This method is passed a scalar and is expected to return an Email::Abstract | ||||||||||||||||||||||||||||
| 63 | #pod object. You probably shouldn't override it in most cases. | ||||||||||||||||||||||||||||
| 64 | #pod | ||||||||||||||||||||||||||||
| 65 | #pod =cut | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 35 | ▶ | sub prepare_email { | ||||||||||||||||||||||||||
|
Subroutine
prepare_email: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 35 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 35 | ▶ | Carp::confess("no email passed in to sender") unless defined $msg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # We check blessed because if someone would pass in a large message, in some | ||||||||||||||||||||||||||||
| 73 | # perls calling isa on the string would create a package with the string as | ||||||||||||||||||||||||||||
| 74 | # the name. If the message was (say) two megs, now you'd have a two meg hash | ||||||||||||||||||||||||||||
| 75 | # key in the stash. Oops! -- rjbs, 2008-12-04 | ||||||||||||||||||||||||||||
| 76 | 35 | ▶ | return $msg if Scalar::Util::blessed($msg) and eval { $msg->isa('Email::Abstract') }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($msg) and eval {
do {
$msg->isa("Email::Abstract")
}
}
MC/DC100%2/2
builtin::blessed($msg) and eval {
do {
$msg->isa("Email::Abstract")
}
}
builtin::blessed($msg)
eval {
do {
$msg->isa("Email::Abstract")
}
}
Truth table100%3/3
A and B
A= builtin::blessed($msg)B= eval {
do {
$msg->isa("Email::Abstract")
}
}
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 30 | return Email::Abstract->new($msg); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | #pod =method prepare_envelope | ||||||||||||||||||||||||||||
| 82 | #pod | ||||||||||||||||||||||||||||
| 83 | #pod This method is passed a hashref and returns a new hashref that should be used | ||||||||||||||||||||||||||||
| 84 | #pod as the envelope passed to the C<send_email> method. This method is responsible | ||||||||||||||||||||||||||||
| 85 | #pod for ensuring that the F<to> entry is an array. | ||||||||||||||||||||||||||||
| 86 | #pod | ||||||||||||||||||||||||||||
| 87 | #pod =cut | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 30 | ▶ | sub prepare_envelope { | ||||||||||||||||||||||||||
|
Subroutine
prepare_envelope: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 30 | my ($self, $env) = @_; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 30 | my %new_env; | |||||||||||||||||||||||||||
| 93 | 30 | ▶ | $new_env{to} = ref $env->{to} ? $env->{to} : [ grep {defined} $env->{to} ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 30 | $new_env{from} = $env->{from}; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 30 | return \%new_env; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | #pod =method success | ||||||||||||||||||||||||||||
| 100 | #pod | ||||||||||||||||||||||||||||
| 101 | #pod ... | ||||||||||||||||||||||||||||
| 102 | #pod return $self->success; | ||||||||||||||||||||||||||||
| 103 | #pod | ||||||||||||||||||||||||||||
| 104 | #pod This method returns a new Email::Sender::Success object. Arguments passed to | ||||||||||||||||||||||||||||
| 105 | #pod this method are passed along to the Success's constructor. This is provided as | ||||||||||||||||||||||||||||
| 106 | #pod a convenience for returning success from subclasses' C<send_email> methods. | ||||||||||||||||||||||||||||
| 107 | #pod | ||||||||||||||||||||||||||||
| 108 | #pod =cut | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 13 | ▶ | sub success { | ||||||||||||||||||||||||||
|
Subroutine
success: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | 13 | my $success = Email::Sender::Success->new(@_); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 13 | ▶ | no Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 116 | 13 | 1; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||