lib/W3C/LogValidator/Output/Mail.pm untested

filter: Statementstmt 0.0% 0 / 64 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 113 CC 13 SCAR 38.5
CC
13
Cov
0%
finish
90.0
new
12.0
output
12.0
CRAP 46.8
1 # Copyright (c) 2002-2005 the World Wide Web Consortium :
2 # Keio University,
3 # European Research Consortium for Informatics and Mathematics
4 # Massachusetts Institute of Technology.
5 # written by Olivier Thereaux <ot@w3.org> for W3C
6 #
7 # $Id: Mail.pm,v 1.13 2005/09/09 06:33:11 ot Exp $
8  
9 package W3C::LogValidator::Output::Mail;
10 use strict;
11  
12  
13 require Exporter;
14 our @ISA = qw(Exporter);
15 our %EXPORT_TAGS = ( 'all' => [ qw() ] );
16 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
17 our @EXPORT = qw();
18 our $VERSION = sprintf "%d.%03d",q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/;
19  
20  
21 ###########################
22 # usual package interface #
23 ###########################
24 our %config;
25 our $verbose = 1;
26  
27 sub new
28 {
29 my $self = {};
30 my $proto = shift;
31 my $class = ref($proto) || $proto;
32 # configuration for this module
33 if (@_) {%config = %{(shift)};}
34 if (exists $config{verbose}) {$verbose = $config{verbose}}
35 bless($self, $class);
36 return $self;
37 }
38  
39 sub output
40 {
41 my $self = shift;
42 my %results;
43 my $outputstr ="";
44 if (@_) {%results = %{(shift)}}
45 use W3C::LogValidator::Output::Raw;
46 $outputstr = W3C::LogValidator::Output::Raw->output(\%results);
47 print $outputstr if ($verbose >2 ); # debug
48  
49 return $outputstr;
50 }
51  
52  
53 sub finish
54 {
55 # for this module, that means send e-mail to the specified maintainer
56 my $self = shift;
57 if (@_)
58 {
59 my $result_string = shift;
60 my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday) = gmtime(time);
61 $hour = sprintf ( "%02d", $hour);
62 $min = sprintf ( "%02d", $min);
63 $mon ++; # weird 'feature': months run 0-11; days run 1-31 :-(
64 my $date = ($year+1900) .'-'. ($mon>9 ? $mon:"0$mon") .'-'. ($day>9 ? $day:"0$day");
65  
66 if (defined $config{"ServerAdmin"} and $result_string ne "")
67 # we have someone to send the mail to
68 {
69 my $mail_subject = "Logvalidator results";
70 if (defined $config{"Title"})
71 {
72 $mail_subject = $config{"Title"};
73 }
74 $mail_subject = $mail_subject." ($date at $hour:$min GMT)";
75 my $add = $config{"ServerAdmin"};
76 my $mail_from = $add;
77 if (defined $config{"MailFrom"})
78 {
79 $mail_from = $config{"MailFrom"};
80 }
81 use Mail::Sendmail;
82 my %mail = (To => $add,
83 From => "LogValidator <$mail_from>",
84 Subject => "$mail_subject",
85 'X-Mailer' => "Mail::Sendmail version $Mail::Sendmail::VERSION",
86 Message => $result_string );
87 print "Sending Mail to $add...\n" if ($verbose >1 );
88 Mail::Sendmail::sendmail(%mail) or print STDERR $Mail::Sendmail::error;
89 if ($verbose >1 ) { print "OK Mail::Sendmail log:\n", $Mail::Sendmail::log, "\n";}
90 }
91 else { print $result_string; }
92 }
93
94  
95 }
96  
97 package W3C::LogValidator::Output::Mail;
98  
99 1;
100  
101 __END__