Build a table and output it in various formats
use Table::Builder;
my $table = Table::Builder->new(cols => ['Item', 'Value']);
$table->add('Apples', 20);
$table->add('Oranges', 25);
$table->add('Lemons', 5);
print $table->render_as('csv');
What is it?
Rationale ... why?
Concept ... how it works?
Arrayref of columns specified. Each column is Table::Builder::Column object with properties for the column.
Array of rows in the table.
$table->add_row('Apples', 10, 20);
$table->add_row({ Item => 'Apples', Amount => 10, Tax => 20 });
Adds a new row into table.
Two forms are supported, either just values for each column or data passed as named arguments.
$table->add_sep;
$table->add_sep(double => 1);
Adds a separator row into table.
$table->add_summary_row('Apples', sub { sum(@_) }, 20);
$table->add_summary_row({ Item => 'Apples', Amount => sub { sum(@_) }, Tax => 20 });
Adds a new summary (calculated) row into table.
Two forms are supported, either just values for each column or data passed as named arguments.
The parameters supplied to the callback are values of given columns for all normal rows.
my $output = $table->render_as('ascii');
my $output = $table->render_as('ascii', %options);
$table->render_as('ascii', file => 'filename.txt');
$table->render_as('ascii', file => $open_filehandle);
$table->render_as('ascii', file => $open_filehandle, %options);
Renders table into string or file using specified output formatting class. By default it looks for classes in Table::Builder::Output namespace. It allows also fully specified formatter class.
Without any options, the output is just returned as a string from the call. With file option specified, the output is written into supplied filename or filehandle.
All other options are passed directly to formatter class and may affect way the output is rendered.
Roman Hubacek roman.hubacek@centrum.cz
This software is copyright (c) 2011 by Roman Hubacek.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.