Text::UnicodeBox::Table - High level interface providing easy table drawing
my $table = Text::UnicodeBox::Table->new(); $table->add_header('id', 'name'); $table->add_row('1', 'George Washington'); $table->add_row('2', 'Thomas Jefferson'); print $table->render(); # Prints: # ┌────┬───────────────────┐ # │ id │ name │ # ├────┼───────────────────┤ # │ 1 │ George Washington │ # │ 2 │ Thomas Jefferson │ # └────┴───────────────────┘
This module provides an easy high level interface over Text::UnicodeBox.
Pass any arguments you would to "new" in Text::UnicodeBox but with the following additions.
If set, line breaks in cell data will result in new rows rather then breaks in the rendering.
If set, the width of the table will ever exceed the given width. Data will be attempted to fit with wrapping at word boundaries.
If set, wrapping may break words
column_widths => [ undef, 40, 60 ], # First column may be any width but the second and third have specified widths
Specify the exact width of each column, sans padding and box formatting.
my $table = Text::UnicodeBox::Table->new( style => 'horizontal_double ');
You may specify a certain style for the table to be drawn. This may be overridden on a per row basis.
All lines are light.
All lines are heavy.
All lines are double.
All horizontal lines are double, where vertical lines are single.
The lines drawing the header are heavy, all others are light.
$table->add_header({ bottom => 'heavy' }, 'Name', 'Age', 'Address');
Same as add_row but sets the option ('header' => 1)
add_row
Draws one line of output with a border on the top and bottom.
If the first argument to this method is a hashref, it is interpreted as an options hash. This hash takes the following parameters:
What style will be used for all box characters involved in this line of output. Options are: 'light', 'double', 'heavy'
alignment => [ 'right', 'left', 'right' ]
Pass a list of 'right' and 'left', corresponding with the number of columns of output. This will control the alignment of this row, and if passed to add_header, all following rows as well. By default, values looking like a number are aligned to the right, with all other values aligned to the left.
add_header
The header will always be aligned to the left unless you pass this array ref to specify custom alignment.
If set, draw a line above or below the current line.
Same as passing top and bottom to the given style (or the default style style)
top
bottom
style
Returns the width of the table if it were rendered right now without additional rows added.
Copyright (c) 2012 Eric Waters and Shutterstock Images (http://shutterstock.com). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
Eric Waters <ewaters@gmail.com>
To install Text::UnicodeBox, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::UnicodeBox
CPAN shell
perl -MCPAN -e shell install Text::UnicodeBox
For more information on module installation, please visit the detailed CPAN module installation guide.