blib/lib/Log/Log4perl/Appender/SMTP.pm

filter: Statementstmt 66.6% 22 / 33 Branchbran 0.0% 0 / 8 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 51.6% 31 / 60 CC 8 SCAR 25.2
CC
8
Cov
52%
log
30.0
new
4.8
BEGIN
1.0
CRAP 12.4
↑ Summary
1 package Log::Log4perl::Appender::SMTP;
2  
3 1 our @ISA = qw(Log::Log4perl::Appender);
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Net::Domain 'hostfqdn';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Net::SMTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.04';
12  
13 1 ▶sub new {
Subroutine new: called CC=4 SCAR=15.6
Pod undocumented
14 1 my($class, @options) = @_;
15  
16 1 ▶ my $hname = hostfqdn() || '<unknown>';
Condition50%1/2
hostfqdn() || '<unknown>'
l!l
10
MC/DC0%0/1
hostfqdn() || '<unknown>'
hostfqdn()
Truth table50%1/2
A
A= hostfqdn()
Aresult
11
00
17 1 ▶ my $user = getlogin || getpwuid($<) || 'log4perl';
Condition40%2/5
getlogin || getpwuid $< || 'log4perl'
l!l
10
getlogin or getpwuid $<
l!l&&r!l&&!r
010
MC/DC0%0/2
getlogin || getpwuid $< || 'log4perl'
getlogin getpwuid $<
Truth table33%1/3
A or B
A= getloginB= getpwuid $<
ABresult
1X1
011
000
18  
19 1 return bless {
20 from => $user.'@'.$hname,
21 to => 'postmaster',
22 subject => "Subject: Log4perl from $hname\n",
23 Host => 'localhost',
24 @options
25 }, $class;
26 }
27  
28 0 ▶sub log {
Subroutine log: not called CC=5 SCAR=34.0
Pod undocumented
29 0 my ($self, %params) = @_;
30  
31 0 ▶ my $smtp = Net::SMTP->new(%$self) or return
Branch: 1 branch
BranchTrueFalseTotal
my $smtp = "Net::SMTP"->new(%$self) or return carp("log4perl: could not connect to the SMTP server") 0 0 0
32 carp "log4perl: could not connect to the SMTP server";
33  
34 0 ▶ $smtp->mail($self->{from}) or return
Branch: 1 branch
BranchTrueFalseTotal
$smtp->mail($self->{"from"}) or return carp(qq[log4perl: sender rejected: $self->{"from"}]) 0 0 0
35 carp "log4perl: sender rejected: $self->{from}";
36  
37 0 ▶ $smtp->to(split /,/, $self->{to}) or return
Branch: 1 branch
BranchTrueFalseTotal
$smtp->to(split(/,/, $self->{"to"}, 0)) or return carp(qq[log4perl: recipient(s) rejected: $self->{"to"}]) 0 0 0
38 carp "log4perl: recipient(s) rejected: $self->{to}";
39  
40 0 $smtp->data;
41 0 $smtp->datasend("From: ".$self->{from}."\n");
42 0 $smtp->datasend("To: ".$self->{to}."\n");
43 0 $smtp->datasend("Subject: ".$self->{subject}."\n");
44 0 $smtp->datasend("\n" . $params{message} . "\n");
45 0 ▶ $smtp->dataend or carp "log4perl: message could not be sent by smtp";
Branch: 1 branch
BranchTrueFalseTotal
$smtp->dataend or carp("log4perl: message could not be sent by smtp") 0 0 0
46 0 $smtp->quit;
47 }
48  
49 1 1;
50  
51 __END__
↑ Summary