blib/lib/Email/Sender/Util.pm

filter: Statementstmt 100% 56 / 56 Branchbran 80.0% 16 / 20 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 13 / 13 Podpod 100% 1 / 1 totaltotal 94.0% 94 / 100 CC 13 SCAR 17.6
CC
13
Cov
94%
_failure
11.4
_rewrite_class
3.0
BEGIN
1.0
CRAP 5.8
« blib/lib/Email/Sender/Transport/SMTP/Persistent.pm ↑ Summary blib/lib/Email/Sender/Transport/Test.pm »
1 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Email::Sender::Util 2.603;
4 # ABSTRACT: random stuff that makes Email::Sender go
5  
6 8 ▶use Email::Address::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Email::Sender::Failure;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Email::Sender::Failure::Permanent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Email::Sender::Failure::Temporary;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use List::Util 1.45 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Module::Runtime qw(require_module);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # This code will be used by Email::Sender::Simple. -- rjbs, 2008-12-04
14 1 ▶sub _recipients_from_email {
Subroutine _recipients_from_email: called CC=1 SCAR=0.0
15 1 my ($self, $email) = @_;
16  
17 my @to = List::Util::uniq(
18 7 map { $_->address }
19 4 map { Email::Address::XS->parse($_) }
20 1 map { $email->get_header($_) }
21 qw(to cc bcc));
22  
23 1 return \@to;
24 }
25  
26 1 ▶sub _sender_from_email {
Subroutine _sender_from_email: called CC=1 SCAR=0.0
27 1 my ($self, $email) = @_;
28  
29 1 my ($sender) = map { $_->address }
30 1 map { Email::Address::XS->parse($_) }
31 scalar $email->get_header('from');
32  
33 1 return $sender;
34 }
35  
36 # It's probably reasonable to make this code publicker at some point, but for
37 # now I don't want to deal with making a sane set of args. -- rjbs, 2008-12-09
38 7 ▶sub _failure {
Subroutine _failure: called CC=11 SCAR=24.4
39 7 my ($self, $error, $smtp, @rest) = @_;
40  
41 7 my ($code, $message);
42 7 ▶ if ($smtp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($smtp) { } 6 1 7
43 6 $code = $smtp->code;
44 6 $message = $smtp->message;
45 6 ▶ $message = ! defined $message ? "(no SMTP error message)"
Branch: 2 branches
BranchTrueFalseTotal
!defined($message) ? : 0 6 6
!length($message) ? : 0 6 6
46 : ! length $message ? "(empty SMTP error message)"
47 : $message;
48  
49 6 ▶ $message = defined $error && length $error
Branch: 1 branch
BranchTrueFalseTotal
defined $error && length $error ? : 3 3 6
Condition66%2/3
defined $error and length $error
!ll&&!rl&&r
303
MC/DC50%1/2
defined $error and length $error
defined $error length $error
Truth table66%2/3
A and B
A= defined $errorB= length $error
ABresult
0X0
100
111
50 ? "$error: $message"
51 : $message;
52 } else {
53 1 $message = $error;
54 1 ▶ $message = "(no error given)" unless defined $message;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 1 1
55 1 ▶ $message = "(empty error string)" unless length $message;
Branch: 1 branch
BranchTrueFalseTotal
unless length $message 0 1 1
56 }
57  
58 7 ▶ my $error_class = ! $code ? 'Email::Sender::Failure'
Branch: 3 branches
BranchTrueFalseTotal
!$code ? : 1 6 7
$code =~ /^4/ ? : 2 4 6
$code =~ /^5/ ? : 2 2 4
59 : $code =~ /^4/ ? 'Email::Sender::Failure::Temporary'
60 : $code =~ /^5/ ? 'Email::Sender::Failure::Permanent'
61 : 'Email::Sender::Failure';
62  
63 7 $error_class->new({
64 message => $message,
65 code => $code,
66 @rest,
67 });
68 }
69  
70 #pod =method easy_transport
71 #pod
72 #pod my $transport = Email::Sender::Util->easy_transport($class => \%arg);
73 #pod
74 #pod This takes the name of a transport class and a set of args to new. It returns
75 #pod an Email::Sender::Transport object of that class.
76 #pod
77 #pod C<$class> is rewritten to C<Email::Sender::Transport::$class> unless it starts
78 #pod with an equals sign (C<=>) or contains a colon. The equals sign, if present,
79 #pod will be removed.
80 #pod
81 #pod =cut
82  
83 7 ▶sub _rewrite_class {
Subroutine _rewrite_class: called CC=3 SCAR=11.0
84 7 my $transport_class = $_[1];
85 7 ▶ if ($transport_class !~ s/^=// and $transport_class !~ m{:}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($transport_class =~ s/^=// or $transport_class =~ /:/) 3 4 7
Condition100%3/3
$transport_class =~ s/^=// or $transport_class =~ /:/
l!l&&r!l&&!r
223
MC/DC100%2/2
$transport_class =~ s/^=// or $transport_class =~ /:/
$transport_class =~ s/^=// $transport_class =~ /:/
Truth table100%3/3
A or B
A= $transport_class =~ s/^=//B= $transport_class =~ /:/
ABresult
1X1
011
000
86 3 $transport_class = "Email::Sender::Transport::$transport_class";
87 }
88  
89 7 return $transport_class;
90 }
91  
92 3 ▶sub easy_transport {
Subroutine easy_transport: called CC=1 SCAR=0.0
Pod documented
93 3 my ($self, $transport_class, $arg) = @_;
94  
95 3 $transport_class = $self->_rewrite_class($transport_class);
96  
97 3 require_module($transport_class);
98 3 return $transport_class->new($arg);
99 }
100  
101 8 1;
102  
103 __END__
« blib/lib/Email/Sender/Transport/SMTP/Persistent.pm ↑ Summary blib/lib/Email/Sender/Transport/Test.pm »