blib/lib/oEdtk/Messenger.pm

filter: Statementstmt 63.6% 21 / 33 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 46.6% 28 / 60 CC 6 SCAR 30.7
CC
6
Cov
46%
oe_send_mail
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 21.5
« blib/lib/oEdtk/trackEdtk.pm ↑ Summary lib/oEdtk/Ext.pm »
1 package oEdtk::Messenger;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Email::Sender::Simple qw(sendmail);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Email::Sender::Transport::SMTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use oEdtk::Config qw(config_read);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 our $VERSION = 2.1131;
12 2 our @ISA = qw(Exporter);
13 2 our @EXPORT_OK = qw(oe_send_mail);
14  
15 #http://search.cpan.org/~rjbs/Email-Sender-0.120002/lib/Email/Sender/Manual/QuickStart.pm
16  
17 0 ▶sub oe_send_mail {
Subroutine oe_send_mail: not called CC=6 SCAR=37.4
Pod documented
18 0 my ( $to, $subject, @body ) = @_;
19 0 my $cfg = config_read('MAIL');
20 0 ▶ $subject ||= $0;
Condition0%0/3
$subject ||= $0
l!l&&r!l&&!r
000
MC/DC0%0/2
$subject ||= $0
$subject $0
Truth table0%0/3
A ||= B
A= $subjectB= $0
ABresult
1X1
011
000
21 0 $subject = $cfg->{'EDTK_TYPE_ENV'} . " - $subject ";
22  
23 my $transport = Email::Sender::Transport::SMTP->new(
24 {
25 0 host => $cfg->{'EDTK_MAIL_SMTP'}
26 }
27 );
28  
29 my $email = Email::Simple->create(
30 header => [
31 To => $to || $cfg->{'EDTK_MAIL_SENDER'},
32 0 ▶ From => $cfg->{'EDTK_MAIL_SENDER'},
Condition0%0/6
$to || $cfg->{'EDTK_MAIL_SENDER'}
l!l&&r!l&&!r
000
$subject || $0
l!l&&r!l&&!r
000
MC/DC0%0/2
$to || $cfg->{'EDTK_MAIL_SENDER'}
$to $cfg->{'EDTK_MAIL_SENDER'}
MC/DC0%0/2
$subject || $0
$subject $0
Truth table0%0/3
A || B
A= $toB= $cfg->{'EDTK_MAIL_SENDER'}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $subjectB= $0
ABresult
1X1
011
000
33 Subject => $subject || $0
34 ],
35 body => join( '', @body )
36 );
37  
38 # Useful for testing.
39 0 ▶ if ( $cfg->{'EDTK_MAIL_SMTP'} eq 'warn' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cfg->{'EDTK_MAIL_SMTP'} eq 'warn') { } 0 0 0
40 0 print $email->as_string() . "\n";
41 }
42 else {
43 0 eval { sendmail( $email, { transport => $transport } ); };
44 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
45 0 die "ERROR: sendmail failed. Reason is $@\n";
46 }
47 }
48 }
49  
50 =head1 NAME
51  
52 oEdtk::Messenger - send a simple notification email
53  
54 =head1 SYNOPSIS
55  
56 use oEdtk::Messenger qw(oe_send_mail);
57  
58 oe_send_mail('dest@example.com', 'Job report', "done\n");
59  
60 =head1 DESCRIPTION
61  
62 A one-function helper to send a short notification email. The SMTP host and
63 the sender address come from the C<MAIL> section of the oEdtk configuration
64 (read through L<oEdtk::Config>), and the subject is prefixed with the current
65 C<EDTK_TYPE_ENV>.
66  
67 =head1 FUNCTIONS
68  
69 =head2 oe_send_mail
70  
71 oe_send_mail($to, $subject, @body);
72  
73 Build and send an email to C<$to> (defaulting to C<EDTK_MAIL_SENDER>) with the
74 given C<$subject> (prefixed with C<EDTK_TYPE_ENV>, defaulting to C<$0>) and
75 body. When the configured C<EDTK_MAIL_SMTP> is the literal string C<warn>, the
76 message is printed instead of being sent, which is convenient for testing.
77 Dies when the send fails.
78  
79 =head1 AUTHOR
80  
81 The oEdtk team.
82  
83 =cut
« blib/lib/oEdtk/trackEdtk.pm ↑ Summary lib/oEdtk/Ext.pm »