File Coverage

blib/lib/Email/Send/Qmail.pm
Criterion Covered Total %
statement 23 33 69.7
branch 3 12 25.0
condition n/a
subroutine 7 8 87.5
pod 0 2 0.0
total 33 55 60.0


line stmt bran cond sub pod time code
1             package Email::Send::Qmail;
2 2     2   1459 use strict;
  2         2  
  2         68  
3              
4 2     2   9 use File::Spec ();
  2         1  
  2         63  
5             BEGIN {
6 2     2   2 local $Return::Value::NO_CLUCK = 1;
7 2         7 require Return::Value;
8 2         142 Return::Value->import;
9             }
10 2     2   13 use Symbol qw(gensym);
  2         3  
  2         102  
11              
12 2     2   8 use vars qw[$QMAIL $VERSION];
  2         2  
  2         507  
13             $QMAIL ||= q[qmail-inject];
14             $VERSION = '2.201';
15              
16             sub is_available {
17 1     1 0 2 my $class = shift;
18              
19              
20 1 50       2 return failure "No qmail found" unless $class->_find_qmail;
21 0         0 return success;
22             }
23              
24             sub _find_qmail {
25 1     1   1 my $class = shift;
26              
27 1         2 my $sendmail;
28              
29 1 50       7 if (-x $QMAIL) {
30 0         0 return $QMAIL;
31             }
32              
33 1         20 for my $dir (File::Spec->path) {
34 7 50       59 if ( -x "$dir/$QMAIL" ) {
35 0         0 $sendmail = "$dir/$QMAIL";
36 0         0 last;
37             }
38             }
39 1         6 return $sendmail;
40             }
41              
42             sub send {
43 0     0 0   my ($class, $message, @args) = @_;
44              
45 0           my $pipe = gensym;
46              
47 0 0         open $pipe, "| $QMAIL @args"
48             or return failure "couldn't open pipe to qmail";
49              
50 0 0         print $pipe $message->as_string
51             or return failure "couldn't send message to qmail";
52              
53 0 0         close $pipe
54             or return failure "error when closing pipe to qmail";
55              
56 0           return success;
57             }
58              
59             1;
60              
61             __END__