File Coverage

blib/lib/Log/Dispatch/Email/MailSend.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Log::Dispatch::Email::MailSend;
2              
3 1     1   646 use strict;
  1         2  
  1         31  
4 1     1   5 use warnings;
  1         3  
  1         79  
5              
6             our $VERSION = '2.70';
7              
8 1     1   211 use Mail::Send;
  0            
  0            
9             use Try::Tiny;
10              
11             use base qw( Log::Dispatch::Email );
12              
13             sub send_email {
14             my $self = shift;
15             my %p = @_;
16              
17             my $msg = Mail::Send->new;
18              
19             $msg->to( join ',', @{ $self->{to} } );
20             $msg->subject( $self->{subject} );
21              
22             # Does this ever work for this module?
23             $msg->set( 'From', $self->{from} ) if $self->{from};
24              
25             local $? = 0;
26             return
27             if try {
28             my $fh = $msg->open
29             or die 'Cannot open handle to mail program';
30              
31             $fh->print( $p{message} )
32             or die 'Cannot print message to mail program handle';
33              
34             $fh->close
35             or die 'Cannot close handle to mail program';
36              
37             1;
38             };
39              
40             warn $@ if $@;
41             }
42              
43             1;
44              
45             # ABSTRACT: Subclass of Log::Dispatch::Email that uses the Mail::Send module
46              
47             __END__
48              
49             =pod
50              
51             =encoding UTF-8
52              
53             =head1 NAME
54              
55             Log::Dispatch::Email::MailSend - Subclass of Log::Dispatch::Email that uses the Mail::Send module
56              
57             =head1 VERSION
58              
59             version 2.70
60              
61             =head1 SYNOPSIS
62              
63             use Log::Dispatch;
64              
65             my $log = Log::Dispatch->new(
66             outputs => [
67             [
68             'Email::MailSend',
69             min_level => 'emerg',
70             to => [qw( foo@example.com bar@example.org )],
71             subject => 'Big error!'
72             ]
73             ],
74             );
75              
76             $log->emerg('Something bad is happening');
77              
78             =head1 DESCRIPTION
79              
80             This is a subclass of L<Log::Dispatch::Email> that implements the send_email
81             method using the L<Mail::Send> module.
82              
83             =head1 CHANGING HOW MAIL IS SENT
84              
85             Since L<Mail::Send> is a subclass of L<Mail::Mailer>, you can change
86             how mail is sent from this module by simply C<use>ing L<Mail::Mailer>
87             in your code before mail is sent. For example, to send mail via smtp,
88             you could do:
89              
90             use Mail::Mailer 'smtp', Server => 'foo.example.com';
91              
92             For more details, see the L<Mail::Mailer> docs.
93              
94             =head1 SUPPORT
95              
96             Bugs may be submitted at L<https://github.com/houseabsolute/Log-Dispatch/issues>.
97              
98             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
99              
100             =head1 SOURCE
101              
102             The source code repository for Log-Dispatch can be found at L<https://github.com/houseabsolute/Log-Dispatch>.
103              
104             =head1 AUTHOR
105              
106             Dave Rolsky <autarch@urth.org>
107              
108             =head1 COPYRIGHT AND LICENSE
109              
110             This software is Copyright (c) 2020 by Dave Rolsky.
111              
112             This is free software, licensed under:
113              
114             The Artistic License 2.0 (GPL Compatible)
115              
116             The full text of the license can be found in the
117             F<LICENSE> file included with this distribution.
118              
119             =cut