A Text::TabularDisplay instance can be created with column names
passed as constructor args, so these two calls produce similar
Calling new() on a Text::TabularDisplay instance returns a clone of the object. See clone in Text::TabularDisplay.
Gets or sets the column names for an instance. This method is called
automatically by the constructor with any parameters that are passed
to the constructor (if any are passed).
When called in scalar context, columns() returns the number of columns in the instance, rather than the columns themselves. In list context, copies of the columns names are returned; the names of the columns cannot be modified this way.
Takes a list of items and appends it to the list of items to be
displayed. add() can also take a reference to an array, so that large
arrays dont need to be copied.
As elements are processed, add() maintains the width of each column so that the resulting table has the correct dimensions.
add() returns $self, so that calls to add() can be chained:
render() does most of the actual work. It returns a string containing
the data added via add(), formatted as a table, with a header
containing the column names.
render() does not change the state of the object; it can be called multiple times, with identical output (including identical running time: the output of render is not cached).
If there are no columns defined, then the output table does not contains a row of column names. Compare these two sequences:
render() takes optional $start and $end arguments; these indicate the start and end indexes for the data to be rendered. This can be used for paging and the like:
As an aside, note the chaining of calls to add().
The elements in the table are padded such that there is the same number of items in each row, including the header. Thus:
clone() The clone() method returns an identical copy of a Text::TabularDisplay instance, completely separate from the cloned instance. items() The items() method returns the number of elements currently stored in the data structure:
printf "There are %d elements in \$t.\n", $t->items;
reset() Reset deletes the data from the instance, including columns. If passed arguments, it passes them to columns(), just like new(). populate() populate() as a special case of add(); populate() expects a reference to an array of references to arrays, such as returned by DBIs selectall_arrayref method:
$sql = "SELECT " . join(", ", @c) . " FROM mytable"; $t->columns(@c); $t->populate($dbh->selectall_arrayref($sql));
This is for convenience only; the implementation maps this to multiple calls to add().
Text::TabularDisplay assumes it is handling strings, and does stringy things with the data, like length() and sprintf(). Non-character data can be passed in, of course, but will be treated as strings; this may have ramifications for objects that implement overloading.
The biggest issue, though, is that this module duplicates a some of the functionality of Data::ShowTable. Of course, Data::ShowTable is a large, complex monolithic tool that does a lot of things, while Text::TabularDisplay is small and fast.
darren chamberlain <firstname.lastname@example.org>
The following people have contributed patches, suggestions, tests, feedback, or good karma:
David N. Blank-Edelman Eric Cholet Ken Youens-Clark Michael Fowler Paul Cameron Prakash Kailasa Slaven Rezic Harlan Lieberman-Berg Patrick Kuijvenhoven Miko OSullivan
This documentation describes Text::TabularDisplay version 1.38.
|perl v5.20.3||TABULARDISPLAY (3)||2014-07-07|