blib/lib/Email/Sender/Transport/Failable.pm

filter: Statementstmt 92.3% 24 / 26 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 3 totaltotal 82.9% 34 / 41 CC 4 SCAR 7.8
CC
4
Cov
90%
__ANON__
4.0
clear_failure_conditions
2.0
BEGIN
1.0
CRAP 2.2
« blib/lib/Email/Sender/Failure.pm ↑ Summary blib/lib/Email/Sender/Role/CommonSending.pm »
1 package Email::Sender::Transport::Failable 2.603;
2 # ABSTRACT: a wrapper to makes things fail predictably
3  
4 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 extends 'Email::Sender::Transport::Wrapper';
6  
7 2 ▶use MooX::Types::MooseLike::Base qw(ArrayRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 #pod =head1 DESCRIPTION
10 #pod
11 #pod This transport extends L<Email::Sender::Transport::Wrapper>, meaning that it
12 #pod must be created with a C<transport> attribute of another
13 #pod Email::Sender::Transport. It will proxy all email sending to that transport,
14 #pod but only after first deciding if it should fail.
15 #pod
16 #pod It does this by calling each coderef in its C<failure_conditions> attribute,
17 #pod which must be an arrayref of code references. Each coderef will be called and
18 #pod will be passed the Failable transport, the Email::Abstract object, the
19 #pod envelope, and a reference to an array containing the rest of the arguments to
20 #pod C<send>.
21 #pod
22 #pod If any coderef returns a true value, the value will be used to signal failure.
23 #pod
24 #pod =cut
25  
26 has 'failure_conditions' => (
27 isa => ArrayRef,
28 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
29 2 is => 'ro',
30 reader => '_failure_conditions',
31 );
32  
33 2 ▶sub failure_conditions { @{$_[0]->_failure_conditions} }
Subroutine failure_conditions: called CC=1 SCAR=0.0
Pod undocumented
34 1 ▶sub fail_if { push @{shift->_failure_conditions}, @_ }
Subroutine fail_if: called CC=1 SCAR=0.0
Pod undocumented
35 0 ▶sub clear_failure_conditions { @{$_[0]->{failure_conditions}} = () }
Subroutine clear_failure_conditions: not called CC=1 SCAR=6.9
Pod undocumented
36  
37 2 ▶around send_email => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
38 2 my ($orig, $self, $email, $env, @rest) = @_;
39  
40 2 for my $cond ($self->failure_conditions) {
41 2 my $reason = $cond->($self, $email, $env, \@rest);
42 2 ▶ next unless $reason;
Branch: 1 branch
BranchTrueFalseTotal
unless $reason 1 1 2
43 1 ▶ die (ref $reason ? $reason : Email::Sender::Failure->new($reason));
Branch: 1 branch
BranchTrueFalseTotal
ref $reason ? : 0 1 1
44 }
45  
46 1 return $self->$orig($email, $env, @rest);
47 2 };
48  
49 2 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 2 1;
51  
52 __END__
« blib/lib/Email/Sender/Failure.pm ↑ Summary blib/lib/Email/Sender/Role/CommonSending.pm »