File Coverage

blib/lib/Log/Dispatch/Email/EmailSend.pm
Criterion Covered Total %
statement 36 36 100.0
branch 1 2 50.0
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 48 49 97.9


line stmt bran cond sub pod time code
1             package Log::Dispatch::Email::EmailSend;
2              
3 1     1   1030 use strict;
  1         2  
  1         41  
4              
5 1     1   906 use Log::Dispatch::Email;
  1         20845  
  1         34  
6              
7 1     1   24 use base qw( Log::Dispatch::Email );
  1         2  
  1         77  
8              
9 1     1   1365 use Email::Send 2.0;
  1         30349  
  1         10  
10 1     1   48 use Email::Simple::Creator;
  1         3  
  1         33  
11              
12 1     1   5 use Params::Validate qw(validate SCALAR ARRAYREF BOOLEAN);
  1         3  
  1         88  
13             Params::Validate::validation_options( allow_extra => 1 );
14              
15 1     1   6 use vars qw[ $VERSION ];
  1         3  
  1         324  
16              
17             $VERSION = 0.03;
18              
19             1;
20              
21             sub new
22             {
23 1     1 1 491 my $class = shift;
24 1         64 my %p = validate( @_,
25             { mailer => { type => SCALAR,
26             default => 'Sendmail' },
27             mailer_args => { type => ARRAYREF,
28             default => [],
29             },
30             }
31             );
32              
33 1         22 my $self = $class->SUPER::new(%p);
34              
35 1 50       259 $self->{to} = join ', ', @{ $self->{to} } if ref $self->{to};
  1         4  
36              
37 1         3 $self->{mailer} = $p{mailer};
38 1         2 $self->{mailer_args} = $p{mailer_args};
39              
40 1         9 return $self;
41             }
42              
43             sub send_email
44             {
45 1     1 1 150 my $self = shift;
46 1         4 my %p = @_;
47              
48 1         10 my $email = Email::Simple->create( header =>
49             [ To => $self->{to},
50             From => $self->{from},
51             Subject => $self->{subject},
52             ],
53             body => $p{message},
54             );
55              
56 1         12 my $sender = Email::Send->new( { mailer => $self->{mailer},
57 1         6555 @{ $self->{mailer_args} },
58             },
59             );
60              
61 1         2784 local $?;
62 1         5 $sender->send($email);
63             }
64              
65              
66             __END__