File Coverage

blib/lib/Test/Smoke/Mailer/Mail_X.pm
Criterion Covered Total %
statement 9 26 34.6
branch 0 16 0.0
condition 0 7 0.0
subroutine 3 4 75.0
pod 1 1 100.0
total 13 54 24.0


line stmt bran cond sub pod time code
1             package Test::Smoke::Mailer::Mail_X;
2 3     3   19 use warnings;
  3         6  
  3         129  
3 3     3   15 use strict;
  3         5  
  3         100  
4              
5             our $VERSION = '0.016';
6              
7 3     3   14 use base 'Test::Smoke::Mailer::Base';
  3         6  
  3         1064  
8              
9             =head1 Test::Smoke::Mailer::Mail_X
10              
11             This handles sending the message with either the B or B program.
12              
13             =head1 DESCRIPTION
14              
15             =head2 Test::Smoke::Mailer::Mail_X->new( %args )
16              
17             Keys for C<%args>:
18              
19             * ddir
20             * mailbin/mailxbin
21             * to
22             * cc
23             * v
24              
25             =cut
26              
27             =head2 $mailer->mail( )
28              
29             C sets up the commandline and body and pipes it to either the
30             B or the B program.
31              
32             =cut
33              
34             sub mail {
35 0     0 1   my $self = shift;
36              
37 0   0       my $mailer = $self->{mailbin} || $self->{mailxbin};
38              
39 0           my $subject = $self->fetch_report();
40 0           my $cc = $self->_get_cc( $subject );
41              
42 0           my $cmdline = qq|$mailer -s '$subject'|;
43 0 0 0       $self->{swcc} ||= '-c', $cmdline .= qq| $self->{swcc} '$cc'| if $cc;
44             $self->{swbcc} ||= '-b', $cmdline .= qq| $self->{swbcc} '$self->{bcc}'|
45 0 0 0       if $self->{bcc};
46 0           $cmdline .= qq| $self->{to}|;
47              
48 0 0         $self->{v} > 1 and print "[$cmdline]\n";
49 0 0         $self->{v} and print "Sending report to $self->{to} ";
50 0           local *MAILER;
51 0 0         if ( open MAILER, "| $cmdline " ) {
52 0           print MAILER $self->{body};
53             close MAILER or
54 0 0         $self->{error} = "Error in pipe to '$mailer': $! (" . $?>>8 . ")";
55             } else {
56 0           $self->{error} = "Cannot fork '$mailer': $!";
57             }
58 0 0         $self->{v} and print $self->{error} ? "not OK\n" : "OK\n";
    0          
59              
60 0           return ! $self->{error};
61             }
62              
63             1;
64              
65             =head1 COPYRIGHT
66              
67             (c) 2002-2013, All rights reserved.
68              
69             * Abe Timmerman
70              
71             This library is free software; you can redistribute it and/or modify
72             it under the same terms as Perl itself.
73              
74             See:
75              
76             * ,
77             *
78              
79             This program is distributed in the hope that it will be useful,
80             but WITHOUT ANY WARRANTY; without even the implied warranty of
81             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
82              
83             =cut