perl/modules/W3C/LogValidator/lib/W3C/LogValidator/Output Mail.pm,1.3,1.4 Raw.pm,1.3,1.4

Update of /sources/public/perl/modules/W3C/LogValidator/lib/W3C/LogValidator/Output
In directory hutz:/tmp/cvs-serv4976

Modified Files:
	Mail.pm Raw.pm 
Log Message:
pretty print for raw output, nuking redundant code in e-mail output

Index: Raw.pm
===================================================================
RCS file: /sources/public/perl/modules/W3C/LogValidator/lib/W3C/LogValidator/Output/Raw.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Raw.pm	5 Apr 2004 04:26:07 -0000	1.3
+++ Raw.pm	2 Jun 2004 07:38:39 -0000	1.4
@@ -36,8 +36,58 @@
         return $self;
 }
 
+
+sub width
+{
+        my $self = shift;
+	my $column_num = shift;
+	my %results = %{(shift)};
+	my @thead = @{$results{"thead"}};
+	my @trows = @{$results{"trows"}};
+	my $headerwidth= length($thead[$column_num]);
+	my $columnwidth = 0;
+	my $cellwidth = 0;
+	my @tcolumn;
+	while (@trows) 
+	{
+		my @row=@{shift (@trows)};
+		$cellwidth = length($row[$column_num]);
+		if ($cellwidth > $columnwidth) { $columnwidth = $cellwidth; }
+	}
+	if ($columnwidth > $headerwidth+1) 
+	{ 
+		return $columnwidth+1; 
+	}
+	else
+	{
+		return $headerwidth+2;
+	}
+
+}
+
+sub spaces
+{
+	my $self = shift;
+	my $spaces = shift;
+	my $bloat = "";
+	for (my $i=0; $i<$spaces; $i++)
+	{ $bloat = $bloat." "; } # lame, innit?
+	return $bloat;
+}
+
+sub dashes
+{
+	my $self = shift;
+	my $spaces = shift;
+	my $bloat = "";
+	for (my $i=0; $i<$spaces; $i++)
+	{ $bloat = $bloat."-"; } # lame, innit?
+	return $bloat;
+}
+
 sub output
 {
+	use POSIX;
 	my $self = shift;
 	my %results;
 	my $outputstr ="";
@@ -48,22 +98,49 @@
 ************************************************************************\n";
 	$outputstr= $outputstr.$results{"intro"}."\n\n" if ($results{"intro"});
 	my @thead = @{$results{"thead"}};
+	my $column_num = 0;
+	my $all_columns = int(@thead);
+	my @widths;
+	# printing table headers
 	while (@thead)
 	{
 		my $header = shift (@thead);	
-		$outputstr= $outputstr."$header   ";
+		my $spaces;
+		$widths[$column_num] = $self->width($column_num, \%results);
+		if ($widths[$column_num] > length($header)+2)
+		{
+			$spaces = $widths[$column_num] - length($header)+2;
+		}
+		else { $spaces = 2 }
+		my $space_before= ceil($spaces/2);
+		my $space_after= floor($spaces/2);
+		$outputstr= $outputstr.$self->spaces($space_before);
+		$outputstr= $outputstr."$header";
+		$outputstr= $outputstr.$self->spaces($space_after+1);
+		$column_num = $column_num+1;
+	}
+	$outputstr= $outputstr."\n";
+	
+	# printing separation dashes
+	for ( my $clm = 0; $clm < $all_columns; $clm++)
+	{
+		$outputstr=$outputstr."".$self->dashes($widths[$clm])." ";
 	}
 	$outputstr= $outputstr."\n";
+	# printing the bulk of results table
 	my @trows = @{$results{"trows"}};
 	while (@trows)
 	{
+		my $column_num = 0;
 		my @row=@{shift (@trows)};
 		my $tcell;
 		while (@row)
 		{
 			$tcell= shift (@row);	
 			chomp $tcell;
-			$outputstr= $outputstr."$tcell   	";
+			my $spaces = $widths[$column_num] - length($tcell);
+			$outputstr= $outputstr."$tcell".$self->spaces($spaces+1);
+			$column_num = $column_num+1;
 		}
 		$outputstr= $outputstr."\n";
 	}

Index: Mail.pm
===================================================================
RCS file: /sources/public/perl/modules/W3C/LogValidator/lib/W3C/LogValidator/Output/Mail.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Mail.pm	28 Mar 2004 19:26:33 -0000	1.3
+++ Mail.pm	2 Jun 2004 07:38:39 -0000	1.4
@@ -42,34 +42,10 @@
 	my %results;
 	my $outputstr ="";
 	if (@_) {%results = %{(shift)}}
-	$outputstr= "
-************************************************************************
-Results for module ".$results{'name'}."
-************************************************************************\n";
-	$outputstr= $outputstr.$results{"intro"}."\n\n" if ($results{"intro"});
-	my @thead = @{$results{"thead"}};
-	while (@thead)
-	{
-		my $header = shift (@thead);	
-		$outputstr= $outputstr."$header   ";
-	}
-	$outputstr= $outputstr."\n";
-	my @trows = @{$results{"trows"}};
-	while (@trows)
-	{
-		my @row=@{shift (@trows)};
-		my $tcell;
-		while (@row)
-		{
-			$tcell= shift (@row);	
-			chomp $tcell;
-			$outputstr= $outputstr."$tcell   ";
-		}
-		$outputstr= $outputstr."\n";
-	}
-	$outputstr= $outputstr."\n";
-	$outputstr= $outputstr.$results{"outro"}."
-************************************************************************\n\n" if ($results{"outro"});
+	use W3C::LogValidator::Output::Raw;
+	$outputstr = W3C::LogValidator::Output::Raw->output(\%results);
+	print $outputstr if ($verbose >2 ); # debug
+
 	return $outputstr;	
 }
 

Received on Wednesday, 2 June 2004 03:38:41 UTC