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

filter: Statementstmt 0.0% 0 / 79 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 126 CC 13 SCAR 34.7
CC
13
Cov
0%
output
42.0
finish
42.0
new
12.0
CRAP 32.0
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: HTML.pm,v 1.13 2005/09/09 06:33:11 ot Exp $
8  
9 package W3C::LogValidator::Output::HTML;
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 $verbose = 1;
25 our %config;
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 (defined $config{verbose}) {$verbose = $config{verbose}}
35 bless($self, $class);
36 return $self;
37 }
38  
39  
40  
41  
42 sub output
43 {
44 my $self = shift;
45 my %results;
46 my $outputstr ="";
47 if (@_) {%results = %{(shift)}}
48 $outputstr= "
49 <h2>Results for module ".$results{'name'}."</h2>\n";
50 $outputstr= $outputstr."<p>".$results{"intro"}."</p>\n" if ($results{"intro"});
51 my @thead = @{$results{"thead"}};
52 my @trows = @{$results{"trows"}};
53 if ((@thead) or (@trows))
54 {
55 $outputstr= $outputstr."<table>\n";
56 if (@thead)
57 {
58 $outputstr= $outputstr."<tr>\n";
59 while (@thead)
60 {
61 my $header = shift (@thead);
62 $outputstr= $outputstr."<th>$header</th>";
63 }
64 $outputstr= $outputstr."</tr>\n";
65 }
66 while (@trows)
67 {
68 my @row=@{shift (@trows)};
69 $outputstr= $outputstr."<tr>\n";
70 my $tcell;
71 while (@row)
72 {
73 $tcell= shift (@row);
74 chomp $tcell;
75 $outputstr= $outputstr."<td>$tcell</td>";
76 }
77 $outputstr= $outputstr."</tr>\n";
78 }
79 $outputstr= $outputstr."</table>\n";
80 }
81 $outputstr= $outputstr."\n";
82 $outputstr= $outputstr."<p>".$results{"outro"}."</p>\n\n" if ($results{"outro"});
83 return $outputstr;
84 }
85  
86 sub finish
87 {
88 # embed HTML tidbits in a full HTML file
89 # and either save or output
90 my $self = shift;
91  
92  
93 my $title = "Logvalidator results";
94 if (defined $config{"Title"})
95 {
96 $title = $config{"Title"};
97 }
98  
99 my $result_string = '<?xml version="1.0" encoding="iso-8859-1"?>
100 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
101 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
102 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
103 <head>
104 <title>'.$title.'</title>
105 <style type="text/css" media="screen">
106 h1
107 {
108 text-align: center;
109 color : #424242;
110  
111 }
112 h2 {
113 background: #999;
114 color: white;
115 border: none;
116 width: 100%;
117 font-weight: bold;
118 font-size: 1.3em;
119 text-indent: 0.5em;
120 margin-top: 0.5em;
121 padding: 0.1em;
122 }
123 table {
124 font-size:100%;
125 width:90%;
126 border: 1px solid #999;
127 border-spacing: 0px;
128 }
129 th,td
130 {
131 text-align:left;
132 border: 1px solid #999;
133 padding-left : .5em;
134 padding-right : .5em;
135 }
136 th
137 {
138 color : #424242;
139 }
140 p.footer
141 {
142 font-size: small;
143 border-top: 1px solid #999;
144 }
145 </style>
146 <link rel="Stylesheet" href="http://www.w3.org/QA/Tools/LogValidator/logvalstyle" />
147 </head>
148 <body>
149 <h1>'.$title.'</h1>';
150  
151 if (@_)
152 {
153 my $tmp_result_string = shift;
154 $result_string = $result_string.$tmp_result_string;
155 }
156 my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday) = gmtime(time);
157 $mon ++; # weird 'feature': months run 0-11; days run 1-31 :-(
158 my $date = ($year+1900) .'-'. ($mon>9 ? $mon:"0$mon") .'-'. ($day>9 ? $day:"0$day");
159  
160 $result_string = $result_string.'
161 <p class="footer">Generated on'." $date at $hour:$min:$sec".' GMT
162 by the <a href="http://www.w3.org/QA/Tools/LogValidator/">Log Validator</a>.</p>
163 </body>
164 </html>';
165  
166 if (defined $config{OutputTo})
167 {
168 my $filetosave = $config{OutputTo};
169 open (HTMLOUT, "> $filetosave")
170 || print STDERR "could not open file $filetosave for saving : $!";
171 print HTMLOUT $result_string;
172 close HTMLOUT;
173 }
174 else
175 {
176 print $result_string;
177 }
178 }
179  
180 package W3C::LogValidator::Output::HTML;
181  
182 1;
183  
184 __END__