602
|
1 |
# Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
# All rights reserved.
|
|
3 |
# This component and the accompanying materials are made available
|
|
4 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
# which accompanies this distribution, and is available
|
|
6 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
#
|
|
8 |
# Initial Contributors:
|
|
9 |
# Nokia Corporation - initial contribution.
|
|
10 |
#
|
|
11 |
# Contributors:
|
|
12 |
#
|
|
13 |
# Description:
|
|
14 |
#
|
|
15 |
#
|
|
16 |
# Description:
|
|
17 |
# TableFormatter/Text.pm
|
|
18 |
#
|
|
19 |
|
|
20 |
package TableFormatter::Text;
|
|
21 |
|
|
22 |
use strict;
|
|
23 |
use TableFormatter;
|
|
24 |
use vars qw/@ISA/;
|
|
25 |
@ISA = qw(TableFormatter);
|
|
26 |
|
|
27 |
sub PrintTable {
|
|
28 |
my $self = shift;
|
|
29 |
my $data = shift;
|
|
30 |
my $doHeading = shift;
|
|
31 |
unless (defined $doHeading) {
|
|
32 |
$doHeading = 0;
|
|
33 |
}
|
|
34 |
|
|
35 |
my $colWidths = $self->FindColWidths($data);
|
|
36 |
my $numRows = scalar(@$data);
|
|
37 |
for (my $row = 0; $row < $numRows; ++$row) {
|
|
38 |
if ($doHeading and $row == 1) {
|
|
39 |
print "\n";
|
|
40 |
}
|
|
41 |
$self->PrintRow($data, $colWidths, $row);
|
|
42 |
}
|
|
43 |
}
|
|
44 |
|
|
45 |
## Private
|
|
46 |
|
|
47 |
sub PrintRow {
|
|
48 |
my $self = shift;
|
|
49 |
my $data = shift;
|
|
50 |
my $colWidths = shift;
|
|
51 |
my $row = shift;
|
|
52 |
my $numCols = scalar(@{$data->[$row]});
|
|
53 |
for (my $col = 0; $col < $numCols; ++$col) {
|
|
54 |
my $this = $data->[$row][$col];
|
|
55 |
$this = '<UNDEFINED>' unless defined $this;
|
|
56 |
print $this, ' ' x ($colWidths->[$col] - length($this));
|
|
57 |
}
|
|
58 |
print "\n";
|
|
59 |
}
|
|
60 |
|
|
61 |
1;
|
|
62 |
|
|
63 |
__END__
|
|
64 |
|
|
65 |
=head1 NAME
|
|
66 |
|
|
67 |
TableFormatter/Text.pm - Formats tables in text
|
|
68 |
|
|
69 |
=head1 INTERFACE
|
|
70 |
|
|
71 |
=head2 New
|
|
72 |
|
|
73 |
Creates a formatter.
|
|
74 |
|
|
75 |
=head2 PrintTable
|
|
76 |
|
|
77 |
Prints the table. Two arguments: firstly, a 2D array of the data. Secondly, a Boolean specifying whether the first row is a header row.
|
|
78 |
|
|
79 |
=head1 KNOWN BUGS
|
|
80 |
|
|
81 |
None.
|
|
82 |
|
|
83 |
=head1 COPYRIGHT
|
|
84 |
|
|
85 |
Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
86 |
All rights reserved.
|
|
87 |
This component and the accompanying materials are made available
|
|
88 |
under the terms of the License "Eclipse Public License v1.0"
|
|
89 |
which accompanies this distribution, and is available
|
|
90 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
91 |
|
|
92 |
Initial Contributors:
|
|
93 |
Nokia Corporation - initial contribution.
|
|
94 |
|
|
95 |
Contributors:
|
|
96 |
|
|
97 |
Description:
|
|
98 |
|
|
99 |
|
|
100 |
=cut
|