Data-ShowTable
view release on metacpan or search on metacpan
ShowTable.pm view on Meta::CPAN
out $title_line;
out $dashes;
}
my @values;
my @prefix = (" ", "<");
my @suffix = (" |", ">|");
my @cell;
# loop over the data, formatting it into cells, one row at a time.
while ((@values = &$row_sub(0)), $#values >= $[) {
# first pass -- format each value into a string
@cell = ();
for ($c = 0; $c <= $#values; $c++) {
$cell[$c] = &$fmt_sub($values[$c], $types->[$c], $max_widths->[$c],
$widths->[$c], $precision->[$c], 'box');
}
# second pass -- output each cell, wrapping if necessary
my $will_wrap;
my $wrapped = 0;
do { $will_wrap = 0;
ShowTable.pm view on Meta::CPAN
$title_line .= ' ';
}
out $title_line if $#$titles >= 0;
out $dashes;
my @values;
my @prefix = (" ", "<");
my @suffix = (" ", ">");
while ((@values = &$row_sub(0)), $#values >= $[) {
# first pass -- format each value into a string
my @cell;
for ($c = 0; $c <= $#values; $c++) {
$cell[$c] = &$fmt_sub($values[$c], $types->[$c], $max_widths->[$c],
$widths->[$c], $precision->[$c], 'table');
}
# second pass -- output each cell, wrapping if necessary
my $will_wrap;
my $wrapped = 0;
do { $will_wrap = 0;
ShowTable.pm view on Meta::CPAN
if (($x = $#$tsuffixes) >= 0) {
$title_line .= $tsuffixes->[$c > $x ? $x : $c];
}
}
$title_line .= "</TH>\n";
}
out $title_line;
out "</TR>";
my ($href, $key, $val, $out);
while ((@values = &$row_sub(0)), $#values >= $[) {
out "<TR> ";
# Walk through the values
for ($c = 0; $c <= $#values; $c++) {
$out = "<TD";
if (defined($val = $values[$c])) { # only worry about defined values
# In HTML mode, all CHAR, TEXT, SYMBOL, or STRING data should
# be escaped to protect HTML syntax "<", ">", "\", and "&".
if ($types->[$c] =~ /char|text|symbol|string/i) {
$val = &htmltext($val) unless $no_escape;
$out .= " ALIGN=LEFT";
ShowTable.pm view on Meta::CPAN
my ($num_cols, $widths, $precision, $max_widths) =
&calc_widths($col_widths, $titles, $rewindable,
$row_sub, $fmt_sub, $types, 'list', '');
my $fmt = sprintf("%%-%ds : %%s\n", ($#$titles >= 0 ? &max_length($titles) : 8));
my @values;
my ($value, $c, $cut, $line);
my $col_limit = $max_width - 2;
while ((@values = &$row_sub(0)), $#values >= $[) {
for ($c = 0; $c <= $#values; $c++) {
# get this column's title
$title = $#$titles >= 0 ? $titles->[$c] : sprintf("Field_%d", $c+1);
my $type = $types->[$c];
my $width = 0;
my $prec = $precision->[$c];
$value = &$fmt_sub($values[$c], $type, 0, $width, $prec, 'list');
while (length($value)) {
if (length($value) > ($cut = $col_limit)) {
$line = substr($value, 0, $cut);
ShowTable.pm view on Meta::CPAN
# If the data is rewindable, scan and accumulate *actual* widths for
# each column, using the title lengths as a minimum.
if ($rewindable) {
my @values;
my @prectype;
if (ref($types) eq 'ARRAY') {
@prectype = map {/float|num(eric|ber)|money|dec|real|precision|double/i } @$types;
}
# Scan the values
while ((@values = &$row_sub(0)), $#values >= $[) {
# If the new row is larger than the number of titles, adjust
# the info arrays..
if ($num_cols < 1 + $#values) { # new column?
$num_cols = 1 + $#values; # new # of columns
for ($c = $#expandable + 1; $c <= $#values; $c++) {
$expandable[$c] = 1;
$precision[$c] = '';
$setprec[$c] = 1;
$max_widths[$c] = 0;
}
/^$/ && return 'null'; # null type
/^([01tf]|yes|no|on|off)$/i && return 'bool'; # 0, 1, yes, no, on, off, t, f
m=^\d{2,4}[-/.]\d{1,2}[-/.]\d{1,2}$= && return 'date'; # mm/dd/yy, yy/mm/dd, yyyy.mm.dd, yyyy-mm-dd
m=^\d{1,2}[-/.]\d{1,2}[-/.]\d{2,4}$= && return 'date'; # dd.mm.yyyy, d.m.yy, dd-mm-yy
/^\w{3,9} \d{1,2}, \d{4}/ && return 'date'; # mmmm dd, yyyy
/^\d{1,2}[- ]\w{3}[- ]\d{2,4}$/ && return 'date'; # dd mmm yyyy
/^\d\d:\d\d(:\d\d)?$/ && return 'time'; # hh:mm:ss
/^[-+]?\d+$/ && return 'int'; # +-nnnn
/^[-+]?[\d.]+(E[+-]?\d+)?$/ && return 'real'; # +-nnn.nnn(E+-nn)
/^[-+]?[\d.]\%$/ && return 'pct'; # nn%, nn.n%, -nn.nnn%
/^-?\(?\$[ \d,.]+\)?(?: *CR)?$/ && return 'money'; # $ nn,nnn.nn or ($ nnn,nnn.nn)
/^-?\(?[\d]+,[\d,]+(\.(\d\d)?)?\)?$/&& return 'money'; # nnn,nnn.nn or ( nnn,nnn.nn)
/^['"]|["']$/ && return 'string'; # "xxxx"
/^\w+$/ && return 'symbol';
/\n/ && return 'text';
return 'char';
}
# Do type conversion
sub new_type {
( run in 0.676 second using v1.01-cache-2.11-cpan-cc502c75498 )