CC: | davidnicol [...] gmail.com |
Subject: | Need option to output to string |
There does not seem to be a way to get a string out of the table
object, when you want to put the table in a string instead of directly
sending it to STDOUT. Which is a very important feature that allows
insertion of EditableTable elements into templates. I don't know how
deep of a refactoring adding that feature will take, but I was
surprised that the htmlDisplay method was not a wrapper around such.
Possible APIs would include letting htmlDisplay take an optional
argument which would be where the output goes, defaulting to stdout,
or a new method, htmlString, and making htmlDisplay a wrapper around
that:
sub htmlDisplay{ print $_[0]->htmlString }
I think there is a way in newer perls to open a virtual file handle to
a string, which would allow htmlString to wrap the current htmlDisplay
---
sub HTML::EditableTable::htmlString {
local *STDOUT;
my $buffer;
open STDOUT, '>', \$buffer or die "Can't reopen STDOUT to buffer: $!";
$_[0]->htmlDisplay;
close STDOUT; # might not be needed
$buffer
}