NAME
Text::UnicodeBox::Table - High level interface providing easy table drawing
SYNOPSIS
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 │
# └────┴───────────────────┘
DESCRIPTION
This module provides an easy high level interface over Text::UnicodeBox.
METHODS
new
Pass any arguments you would to "new" in Text::UnicodeBox but with the following additions.
- split_lines
-
If set, line breaks in cell data will result in new rows rather then breaks in the rendering.
- max_width
-
If set, the width of the table will ever exceed the given width. Data will be attempted to fit with wrapping at word boundaries.
- break_words
-
If set, wrapping may break words
- column_widths
-
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.
- style
-
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.
- light
-
All lines are light.
- heavy
-
All lines are heavy.
- double
-
All lines are double.
- horizontal_double
-
All horizontal lines are double, where vertical lines are single.
- heavy_header
-
The lines drawing the header are heavy, all others are light.
add_header ( [\%opt,] @parts )
$table->add_header({ bottom => 'heavy' }, 'Name', 'Age', 'Address');
Same as add_row
but sets the option ('header' => 1)
Draws one line of output with a border on the top and bottom.
add_row ( [\%opt,] @parts )
If the first argument to this method is a hashref, it is interpreted as an options hash. This hash takes the following parameters:
- style (default: 'light')
-
What style will be used for all box characters involved in this line of output. Options are: 'light', 'double', 'heavy'
- alignment
-
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. - header_alignment
-
The header will always be aligned to the left unless you pass this array ref to specify custom alignment.
- top
- bottom
-
If set, draw a line above or below the current line.
- header
-
Same as passing
top
andbottom
to the given style (or the default stylestyle
)
output_width
Returns the width of the table if it were rendered right now without additional rows added.
COPYRIGHT
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.
AUTHOR
Eric Waters <ewaters@gmail.com>