MMM/Report/Mail.pm

filter: Statementstmt 35.7% 10 / 28 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 42.8% 3 / 7 Podpod 100% 2 / 2 totaltotal 21.7% 15 / 69 CC 11 SCAR 33.6
CC
11
Cov
19%
body_queue
56.0
_get_mail_send
20.0
_send_mail
6.0
CRAP 28.8
« MMM/Batch.pm ↑ Summary MMM/Report/Console.pm »
1 package MMM::Report::Mail;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use base qw(MMM::Report);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Mail::Send;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 MMM::Report::Console
10  
11 =head1 SYNOPSIS
12  
13 use MMM::Report::Console;
14 my $mmm = MMM::Report::Console->new( configfile => $file );
15 $mmm->run();
16  
17 =head1 DESCRIPTION
18  
19 Produce textual report of MMM work done.
20  
21 =head1 SEE ALSO
22  
23 L<MMM>
24 L<MMM::Report>
25 L<MMM::Html>
26  
27 =cut
28  
29 0 ▶sub body_queue {
Subroutine body_queue: not called CC=7 SCAR=40.3
Pod documented
30 0 my ($self, $queue, %info) = @_;
31 0 ▶ my $fh = $self->_get_mail_send() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fh = $self->_get_mail_send or return 0 0 0
32 0 ▶ %info = $queue->state_info() if (!keys %info);
Branch: 1 branch
BranchTrueFalseTotal
unless keys %info 0 0 0
33 0 print $fh sprintf("%s (%s)\n", $queue->name, $queue->dest);
34 print $fh sprintf(" last %s end %s\n",
35 $info{job}{success} ? 'mirror' : 'try',
36 0 ▶ $info{job}{end} ? scalar (gmtime($info{job}{end})) : '(N/A)',
Branch: 2 branches
BranchTrueFalseTotal
$info{'job'}{'success'} ? : 0 0 0
$info{'job'}{'end'} ? : 0 0 0
37 );
38 0 ▶ if (!$info{job}{success} && $info{success}{end}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $info{"job"}{"success"} and $info{"success"}{"end"}) 0 0 0
Condition0%0/3
not $info{"job"}{"success"} and $info{"success"}{"end"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $info{"job"}{"success"} and $info{"success"}{"end"}
not $info{"job"}{"success"} $info{"success"}{"end"}
Truth table0%0/3
not(A) and B
A= not $info{"job"}{"success"}B= $info{"success"}{"end"}
ABresult
0X0
100
111
39 0 print $fh sprintf(" last mirror succefully done %s\n", scalar (gmtime($info{success}{end})));
40 }
41 0 print $fh "\n";
42 }
43  
44 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
45 0 my ($self) = @_;
46 0 MMM::Report::run($self);
47 0 $self->_send_mail();
48 }
49  
50 0 ▶sub _get_mail_send {
Subroutine _get_mail_send: not called CC=4 SCAR=30.0
51 0 my ($self) = @_;
52 $self->{mailsend} ||= Mail::Send->new(
53 To => $self->configval( 'default', 'mailto' ) || $ENV{USER},
54 0 ▶ Subject => 'MMM Report from ' . $self->hostname
Condition0%0/6
$self->{"mailsend"} ||= "Mail::Send"->new("To", $self->configval("default", "mailto") || $ENV{"USER"}, "Subject", 'MMM Report from ' . $self->hostname)
l!l&&r!l&&!r
000
$self->configval('default', 'mailto') || $ENV{'USER'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"mailsend"} ||= "Mail::Send"->new("To", $self->configval("default", "mailto") || $ENV{"USER"}, "Subject", 'MMM Report from ' . $self->hostname)
$self->{"mailsend"} "Mail::Send"->new("To", $self->configval("default", "mailto") || $ENV{"USER"}, "Subject", 'MMM Report from ' . $self->hostname)
MC/DC0%0/2
$self->configval('default', 'mailto') || $ENV{'USER'}
$self->configval('default', 'mailto') $ENV{'USER'}
Truth table0%0/3
A ||= B
A= $self->{"mailsend"}B= "Mail::Send"->new("To", $self->configval("default", "mailto") || $ENV{"USER"}, "Subject", 'MMM Report from ' . $self->hostname)
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $self->configval('default', 'mailto')B= $ENV{'USER'}
ABresult
1X1
011
000
55 );
56 0 ▶ $self->{fh} ||= $self->{mailsend}->open;
Condition0%0/3
$self->{"fh"} ||= $self->{"mailsend"}->open
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"fh"} ||= $self->{"mailsend"}->open
$self->{"fh"} $self->{"mailsend"}->open
Truth table0%0/3
A ||= B
A= $self->{"fh"}B= $self->{"mailsend"}->open
ABresult
1X1
011
000
57 }
58  
59 0 ▶sub _send_mail {
Subroutine _send_mail: not called CC=2 SCAR=17.9
60 0 my ($self) = @_;
61 0 ▶ my $fh = $self->{fh} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fh = $self->{"fh"} or return 0 0 0
62 0 print $fh sprintf("\n-- \nMMM :: %s\n", $MMM::VERSION);
63 0 $fh->close;
64 }
65  
66 2 1;
67  
68 =head1 AUTHOR
69  
70 Olivier Thauvin <nanardon@nanardon.zarb.org>
71  
72 =head1 COPYRIGHT AND LICENSE
73  
74 Copyright (C) 2006 Olivier Thauvin
75  
76 This program is free software; you can redistribute it and/or
77 modify it under the terms of the GNU General Public License
78 as published by the Free Software Foundation; either version 2
79 of the License, or (at your option) any later version.
80  
81 This program is distributed in the hope that it will be useful,
82 but WITHOUT ANY WARRANTY; without even the implied warranty of
83 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84 GNU General Public License for more details.
85  
86 You should have received a copy of the GNU General Public License
87 along with this program; if not, write to the Free Software
88 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
89  
90 =cut
91  
« MMM/Batch.pm ↑ Summary MMM/Report/Console.pm »