blib/lib/Net/Peep/Mail.pm

filter: Statementstmt 34.1% 29 / 85 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 25 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 42.8% 6 / 14 Podpod 25.0% 2 / 8 totaltotal 21.3% 37 / 173 CC 24 SCAR 42.5
CC
24
Cov
21%
send
182.0
to
20.0
smtp_server
20.0
CRAP 70.1
« blib/lib/Net/Peep/Client/Logparser.pm ↑ Summary blib/lib/Net/Peep/Client.pm »
1 package Net::Peep::Mail;
2  
3 12 require 5.005;
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Net::SMTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Net::Peep::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 require Exporter;
11  
12 12 ▶use vars qw{ @ISA %EXPORT_TAGS @EXPORT_OK @EXPORT $VERSION $LOGGER };
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 12 @ISA = qw(Exporter);
15 12 %EXPORT_TAGS = ( );
16 12 @EXPORT_OK = ( );
17 12 @EXPORT = qw( );
18 12 $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
19  
20 12 $LOGGER = Net::Peep::Log->new();
21  
22 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
23  
24 0 my $self = shift;
25 0 ▶ my $class = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
26 0 my $this = {};
27 0 bless $this, $class;
28  
29 } # end sub new
30  
31 0 ▶sub to {
Subroutine to: not called CC=4 SCAR=30.0
Pod documented
32  
33 0 my $self = shift;
34 0 ▶ $self->{'_TO'} = [] unless exists $self->{'_TO'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_TO"} 0 0 0
35 0 ▶ if (@_) { my @to = @_; $self->{'_TO'} = \@to; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
36 0 ▶ return wantarray ? @{$self->{'_TO'}} : $self->{'_TO'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
37  
38 } # end sub to
39  
40 0 ▶sub from {
Subroutine from: not called CC=2 SCAR=17.9
Pod documented
41  
42 0 my $self = shift;
43 0 ▶ if (@_) { $self->{'_FROM'} = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
44 0 return $self->{'_FROM'};
45  
46 } # end from
47  
48 0 ▶sub smtp_server {
Subroutine smtp_server: not called CC=4 SCAR=30.0
Pod undocumented
49  
50 0 my $self = shift;
51 0 ▶ $self->{'_SMTP_SERVER'} = [] unless exists $self->{'_SMTP_SERVER'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_SMTP_SERVER"} 0 0 0
52 0 ▶ if (@_) { my @smtp_server = @_; $self->{'_SMTP_SERVER'} = \@smtp_server; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
53 0 ▶ return wantarray ? @{$self->{'_SMTP_SERVER'}} : $self->{'_SMTP_SERVER'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
54  
55 } # end sub smtp_server
56  
57 0 ▶sub timeout {
Subroutine timeout: not called CC=2 SCAR=17.9
Pod undocumented
58  
59 0 my $self = shift;
60 0 ▶ if (@_) { $self->{'_TIMEOUT'} = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
61 0 return $self->{'_TIMEOUT'};
62  
63 } # end timeout
64  
65 0 ▶sub subject {
Subroutine subject: not called CC=2 SCAR=17.9
Pod undocumented
66  
67 0 my $self = shift;
68 0 ▶ if (@_) { $self->{'_SUBJECT'} = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
69 0 return $self->{'_SUBJECT'};
70  
71 } # end subject
72  
73 0 ▶sub body {
Subroutine body: not called CC=2 SCAR=17.9
Pod undocumented
74  
75 0 my $self = shift;
76 0 ▶ if (@_) { $self->{'_BODY'} = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
77 0 return $self->{'_BODY'};
78  
79 } # end body
80  
81 0 ▶sub send {
Subroutine send: not called CC=13 SCAR=52.0
Pod undocumented
82  
83 0 my $self = shift;
84  
85 0 my $from = $self->from();
86 0 my $to = join ', ', $self->to();
87 0 my $subject = $self->subject();
88 0 my $body = $self->body();
89  
90 0 my $data = <<"eop";
91 To: $to
92 From: $from
93 Subject: $subject
94  
95 $body
96 eop
97 ;
98  
99 0 my $delivered = 0;
100  
101 0 $LOGGER->debug(7,"Sending e-mail:");
102 0 $LOGGER->debug(7,$data);
103 0 $LOGGER->debug(7,"Trying SMTP servers [".(join ', ', $self->smtp_server())."] ...");
104  
105 0 for my $smtp_server ($self->smtp_server()) {
106  
107 0 ▶ my @smtp_args = $self->timeout()
Branch: 1 branch
BranchTrueFalseTotal
$self->timeout ? : 0 0 0
108 ? ( $smtp_server, Timeout => $self->timeout() )
109 : ( $smtp_server );
110  
111 0 my $smtp = Net::SMTP->new(@smtp_args);
112  
113 0 $LOGGER->debug(7,"Sending e-mail to [$smtp_server] ...");
114  
115 0 ▶ $LOGGER->log("Error instantiating Net::SMTP object. ".
Branch: 1 branch
BranchTrueFalseTotal
unless defined $smtp 0 0 0
Condition0%0/5
defined $smtp || $Net::Peep::Mail::LOGGER->log('Error instantiating Net::SMTP object. ' . "The SMTP server [$smtp_server] may not be accepting mail relay requests.") && (next)
l!l&&r!l&&!r
000
$Net::Peep::Mail::LOGGER->log('Error instantiating Net::SMTP object. ' . "The SMTP server [$smtp_server] may not be accepting mail relay requests.") and next
!ll
00
MC/DC0%0/2
defined $smtp || $Net::Peep::Mail::LOGGER->log('Error instantiating Net::SMTP object. ' . "The SMTP server [$smtp_server] may not be accepting mail relay requests.") && (next)
defined $smtp $Net::Peep::Mail::LOGGER->log('Error instantiating Net::SMTP object. ' . "The SMTP server [$smtp_server] may not be accepting mail relay requests.")
Truth table0%0/3
A || B
A= defined $smtpB= $Net::Peep::Mail::LOGGER->log('Error instantiating Net::SMTP object. ' . "The SMTP server [$smtp_server] may not be accepting mail relay requests.")
ABresult
1X1
011
000
116 "The SMTP server [$smtp_server] may not be accepting mail relay requests.")
117 and next unless defined $smtp;
118  
119 0 ▶ if ($smtp->mail($from) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($smtp->mail($from) and $smtp->to($self->to) and $smtp->data and $smtp->datasend($data) and $smtp->dataend) 0 0 0
Condition0%0/12
$smtp->mail($from) and $smtp->to($self->to) and $smtp->data and $smtp->datasend($data) and $smtp->dataend
!ll&&!rl&&r
000
$smtp->mail($from) and $smtp->to($self->to) and $smtp->data and $smtp->datasend($data)
!ll&&!rl&&r
000
$smtp->mail($from) and $smtp->to($self->to) and $smtp->data
!ll&&!rl&&r
000
$smtp->mail($from) and $smtp->to($self->to)
!ll&&!rl&&r
000
MC/DC0%0/5
$smtp->mail($from) and $smtp->to($self->to) and $smtp->data and $smtp->datasend($data) and $smtp->dataend
$smtp->mail($from) $smtp->to($self->to) $smtp->data $smtp->datasend($data) $smtp->dataend
Truth table0%0/6
A and B and C and D and E
A= $smtp->mail($from)B= $smtp->to($self->to)C= $smtp->dataD= $smtp->datasend($data)E= $smtp->dataend
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
120 $smtp->to($self->to()) &&
121 $smtp->data() &&
122 $smtp->datasend($data) &&
123 $smtp->dataend()) {
124 0 $delivered++;
125 }
126  
127 0 $smtp->quit();
128  
129 0 ▶ $LOGGER->debug(7,"E-mail successfully sent.") and last if $delivered;
Branch: 1 branch
BranchTrueFalseTotal
if $delivered 0 0 0
Condition0%0/5
$delivered && ($Net::Peep::Mail::LOGGER->debug(7, 'E-mail successfully sent.') && (last))
!ll&&!rl&&r
000
$Net::Peep::Mail::LOGGER->debug(7, "E-mail successfully sent.") and last
!ll
00
MC/DC0%0/2
$delivered && ($Net::Peep::Mail::LOGGER->debug(7, 'E-mail successfully sent.') && (last))
$delivered $Net::Peep::Mail::LOGGER->debug(7, "E-mail successfully sent.")
Truth table0%0/3
A && B
A= $deliveredB= $Net::Peep::Mail::LOGGER->debug(7, "E-mail successfully sent.")
ABresult
0X0
100
111
130  
131 }
132  
133 0 ▶ unless ($delivered) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($delivered) 0 0 0
134 0 $LOGGER->log("Error delivering mail to server(s) [".join(',',$self->smtp_server())."].");
135 }
136  
137 0 return $delivered;
138  
139 } # end sub send
140  
141 12 1;
142  
143 __END__
« blib/lib/Net/Peep/Client/Logparser.pm ↑ Summary blib/lib/Net/Peep/Client.pm »