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

filter: Statementstmt 0.0% 0 / 123 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 161 CC 10 SCAR 26.1
CC
10
Cov
0%
output
30.0
new
12.0
width
12.0
CRAP 13.6
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: Raw.pm,v 1.10 2005/09/09 06:33:11 ot Exp $
8  
9 package W3C::LogValidator::Output::Raw;
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.10 $ =~ /(\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  
40 sub width
41 {
42 my $self = shift;
43 my $column_num = shift;
44 my %results = %{(shift)};
45 my @thead = @{$results{"thead"}};
46 my @trows = @{$results{"trows"}};
47 my $headerwidth= length($thead[$column_num]);
48 my $columnwidth = 0;
49 my $cellwidth = 0;
50 my @tcolumn;
51 while (@trows)
52 {
53 my @row=@{shift (@trows)};
54 $cellwidth = length($row[$column_num]);
55 if ($cellwidth > $columnwidth) { $columnwidth = $cellwidth; }
56 }
57 if ($columnwidth > $headerwidth+1)
58 {
59 return $columnwidth;
60 }
61 else
62 {
63 return $headerwidth+2;
64 }
65  
66 }
67  
68 sub spaces
69 {
70 my $self = shift;
71 my $spaces = shift;
72 my $bloat = "";
73 for (my $i=0; $i<$spaces; $i++)
74 { $bloat = $bloat." "; } # lame, innit?
75 return $bloat;
76 }
77  
78 sub dashes
79 {
80 my $self = shift;
81 my $spaces = shift;
82 my $bloat = "";
83 for (my $i=0; $i<$spaces; $i++)
84 { $bloat = $bloat."-"; } # lame, innit?
85 return $bloat;
86 }
87  
88 sub output
89 {
90 use POSIX;
91 my $self = shift;
92 my %results;
93 my $outputstr ="";
94 if (@_) {%results = %{(shift)}}
95 $outputstr= "
96 ************************************************************************
97 Results for module ".$results{'name'}."
98 ************************************************************************\n";
99 $outputstr= $outputstr.$results{"intro"}."\n\n" if ($results{"intro"});
100 my @thead = @{$results{"thead"}};
101 my $column_num = 0;
102 my $all_columns = int(@thead);
103 my @widths;
104 # printing table headers
105 while (@thead)
106 {
107 my $header = shift (@thead);
108 my $spaces;
109 $widths[$column_num] = $self->width($column_num, \%results);
110 if ($widths[$column_num] > (length($header)+2) ) # long content
111 {
112 $spaces = $widths[$column_num] - length($header);
113 }
114 else { $spaces = 2 } # long column header
115 # Header is centered
116 my $space_before= ceil($spaces/2);
117 my $space_after= floor($spaces/2);
118 $outputstr= $outputstr.$self->spaces($space_before);
119 $outputstr= $outputstr."$header";
120 $outputstr= $outputstr.$self->spaces($space_after);
121 $outputstr= $outputstr." "; # column separation space
122 $column_num = $column_num+1;
123 }
124 $outputstr= $outputstr."\n";
125
126 # printing separation dashes
127 for ( my $clm = 0; $clm < $all_columns; $clm++)
128 {
129 $outputstr=$outputstr."".$self->dashes($widths[$clm])." ";
130 }
131 $outputstr= $outputstr."\n";
132 # printing the bulk of results table
133 my @trows = @{$results{"trows"}};
134 while (@trows)
135 {
136 my $column_num = 0;
137 my @row=@{shift (@trows)};
138 my $tcell;
139 while (@row)
140 {
141 $tcell= shift (@row);
142 chomp $tcell;
143 my $spaces = $widths[$column_num] - length($tcell);
144 $outputstr= $outputstr."$tcell".$self->spaces($spaces+1);
145 $column_num = $column_num+1;
146 }
147 $outputstr= $outputstr."\n";
148 }
149 $outputstr= $outputstr."\n";
150 $outputstr= $outputstr.$results{"outro"}."
151 ************************************************************************\n\n" if ($results{"outro"});
152 return $outputstr;
153 }
154
155 sub finish
156 {
157 # well for this output it's not too difficult :)
158 my $self = shift;
159 if (@_)
160 {
161 my $result_string = shift;
162 print $result_string;
163 }
164 }
165  
166 package W3C::LogValidator::Output::Raw;
167  
168 1;
169  
170 __END__