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