Send/Sendmail.pm

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