Skip Menu |

This queue is for tickets about the Text-SimpleTable-AutoWidth CPAN distribution.

Report information
The Basics
Id: 68115
Status: new
Priority: 0/
Queue: Text-SimpleTable-AutoWidth

People
Owner: Nobody in particular
Requestors: daxim [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.04
Fixed in: (no value)



Subject: [PATCH] tables may have 0 rows
When a table is created without any rows and then calling the draw method, Perl throws runtime exceptions trying to dereference arrays which do not exist. The attached patch adds code to take that case into account. It applies cleanly against released v0.04. Please apply and kindly put out a new release as soon as practical. Setting bug severity according to criteria: loss of functionality/ crashes under certain circumstances, no known work-around
Subject: 0001-tables-may-have-0-rows.patch
From bdebd94d56501af57d09a50a8ad3491b0faeec58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20D=C9=AA=E1=B4=87=E1=B4=84=E1=B4=8B=E1=B4=8F=E1=B4=A1=20=E8=BF=AA=E6=8B=89=E6=96=AF?= <daxim@cpan.org> Date: Wed, 11 May 2011 15:38:21 +0200 Subject: [PATCH] tables may have 0 rows --- lib/Text/SimpleTable/AutoWidth.pm | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Text/SimpleTable/AutoWidth.pm b/lib/Text/SimpleTable/AutoWidth.pm index 250c9b8..1da5f14 100644 --- a/lib/Text/SimpleTable/AutoWidth.pm +++ b/lib/Text/SimpleTable/AutoWidth.pm @@ -148,7 +148,7 @@ sub draw { 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,9 @@ sub draw { my $tab = Text::SimpleTable->new(@params); # put rows into drawer - $tab->row(@$_) for @{ $self->rows }; + if ( $self->rows ) { + $tab->row(@$_) for @{ $self->rows }; + } return $tab->draw(); } -- 1.7.3.4