Send/Sendmail.pm

filter: Statementstmt 100% 38 / 38 Branchbran 77.7% 14 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 90.9% 60 / 66 CC 11 SCAR 13.8
CC
11
Cov
93%
send
6.3
_find_sendmail
5.0
is_available
2.0
CRAP 4.0
« Send/Qmail.pm ↑ Summary Send.pm »
1 package Email::Send::Sendmail;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 5 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 BEGIN {
6 5 ▶ local $Return::Value::NO_CLUCK = 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 require Return::Value;
8 5 Return::Value->import;
9 }
10 5 ▶use Symbol qw(gensym);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use vars qw[$SENDMAIL $VERSION];
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 $VERSION = '2.201';
15  
16 sub is_available {
17 8 ▶ my $class = shift;
Subroutine is_available: called CC=2 SCAR=6.9
Pod undocumented
18  
19 # This is RIDICULOUS. Why do we say it's available if it isn't?
20 # -- rjbs, 2006-07-06
21 8 ▶ return success "No Sendmail found" unless $class->_find_sendmail;
Branch: 1 branch
BranchTrueFalseTotal
unless $class->_find_sendmail 3 5 8
22 5 return success '';
23 }
24  
25 sub _find_sendmail {
26 12 ▶ my $class = shift;
Subroutine _find_sendmail: called CC=5 SCAR=16.1
27 12 ▶ return $SENDMAIL if defined $SENDMAIL;
Branch: 1 branch
BranchTrueFalseTotal
if defined $Email::Send::Sendmail::SENDMAIL 6 6 12
28  
29 6 my $sendmail;
30 6 ▶ for my $dir (
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'PERL_EMAIL_SEND_SENDMAIL_NO_EXTRA_PATHS'} ? : 3 3 6
31 File::Spec->path,
32 ($ENV{PERL_EMAIL_SEND_SENDMAIL_NO_EXTRA_PATHS} ? () : (
33 File::Spec->catfile('', qw(usr sbin)),
34 File::Spec->catfile('', qw(usr lib)),
35 ))
36 ) {
37 13 ▶ if ( -x "$dir/sendmail" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-x "$dir/sendmail") 2 11 13
38 2 $sendmail = "$dir/sendmail";
39 2 last;
40 }
41 }
42  
43 6 return $sendmail;
44 }
45  
46 sub send {
47 3 ▶ my ($class, $message, @args) = @_;
Subroutine send: called CC=6 SCAR=18.4
Pod undocumented
48 3 my $mailer = $class->_find_sendmail;
49  
50 3 ▶ return failure "Couldn't find 'sendmail' executable in your PATH"
Branch: 1 branch
BranchTrueFalseTotal
unless $mailer 0 3 3
51 ." and \$".__PACKAGE__."::SENDMAIL is not set"
52 unless $mailer;
53  
54 3 ▶ return failure "Found $mailer but cannot execute it"
Branch: 1 branch
BranchTrueFalseTotal
unless -x $mailer 1 2 3
55 unless -x $mailer;
56
57 2 local $SIG{'CHLD'} = 'DEFAULT';
58  
59 2 my $pipe = gensym;
60  
61 2 ▶ open $pipe, "| $mailer -t -oi @args"
Branch: 1 branch
BranchTrueFalseTotal
open $pipe, "| $mailer -t -oi @args" or return failure("Error executing ${mailer}: $!") 0 2 2
62 or return failure "Error executing $mailer: $!";
63 2 ▶ print $pipe $message->as_string
Branch: 1 branch
BranchTrueFalseTotal
print $pipe $message->as_string or return failure("Error printing via pipe to ${mailer}: $!") 0 2 2
64 or return failure "Error printing via pipe to $mailer: $!";
65 2 ▶ close $pipe
Branch: 1 branch
BranchTrueFalseTotal
close $pipe or return failure("error when closing pipe to ${mailer}: $!") 0 2 2
66 or return failure "error when closing pipe to $mailer: $!";
67 2 return success;
68 }
69  
70 5 1;
71  
72 __END__
« Send/Qmail.pm ↑ Summary Send.pm »