Subject: | Text::SimpleTable::AutoWidth breaks with empty rows |
Date: | Tue, 16 Jul 2013 13:23:18 +0200 (CEST) |
To: | bug-Text-SimpleTable-AutoWidth [...] rt.cpan.org |
From: | "Jochen Lutz" <jlu [...] gmx.de> |
Hi.
T::S::AutoWidth breaks when no rows are set but there are captions.
Following patch fixes it.
--- AutoWidth.orig.pm 2013-07-16 13:14:27.600389568 +0200
+++ AutoWidth.pm 2013-07-16 13:15:43.048389576 +0200
@@ -148,7 +148,7 @@
my @max_width = (2) x $columns;
# calculate max width of each column
- for my $row ( ( $self->captions ? $self->captions : () ), @{ $self->rows } ) {
+ for my $row ( ( $self->captions ? $self->captions : () ), $self->rows ? @{ $self->rows } : () ) {
my @row_width = map { length } @$row;
$#row_width = $columns - 1 if $#row_width >= $columns;
@@ -221,7 +221,7 @@
my $tab = Text::SimpleTable->new(@params);
# put rows into drawer
- $tab->row(@$_) for @{ $self->rows };
+ $tab->row(@$_) for $self->rows ? @{ $self->rows } : ();
return $tab->draw();
}
Sincerely,
Jochen