|
NAME"Text::Table::Manifold" - Render tables in manifold formatsSynopsisThis is scripts/synopsis.pl:#!/usr/bin/env perl use strict; use utf8; use warnings; use warnings qw(FATAL utf8); # Fatalize encoding glitches. use open qw(:std :utf8); # Undeclared streams in UTF-8. use Text::Table::Manifold ':constants'; # ----------- # Set parameters with new(). my($table) = Text::Table::Manifold -> new ( alignment => [ align_left, align_center, align_right, align_center, ] ); $table -> headers(['Homepage', 'Country', 'Name', 'Metadata']); $table -> data( [ ['http://savage.net.au/', 'Australia', 'Ron Savage', undef], ['https://duckduckgo.com/', 'Earth', 'Mr. S. Engine', ''], ]); # Note: Save the data, since render() may update it. my(@data) = @{$table -> data}; # Set parameters with methods. $table -> empty(empty_as_text); $table -> format(format_internal_boxed); $table -> undef(undef_as_text); # Set parameters with render(). print "Format: format_internal_boxed: \n"; print join("\n", @{$table -> render(padding => 1)}), "\n"; print "\n"; $table -> headers(['One', 'Two', 'Three']); $table -> data( [ ['Reichwaldstraße', 'Böhme', 'ʎ ʏ ʐ ʑ ʒ ʓ ʙ ʚ'], ['ΔΔΔΔΔΔΔΔΔΔ', 'Πηληϊάδεω Ἀχιλῆος', 'A snowman: ☃'], ['Two ticks: ✔✔', undef, '<table><tr><td>TBA</td></tr></table>'], ]); # Save the data, since render() may update it. @data = @{$table -> data}; $table -> empty(empty_as_minus); $table -> format(format_internal_boxed); $table -> undef(undef_as_text); $table -> padding(2); print "Format: format_internal_boxed: \n"; print join("\n", @{$table -> render}), "\n"; print "\n"; # Restore the saved data. $table -> data([@data]); # Etc. This is data/synopsis.log, the output of synopsis.pl: Format: format_internal_boxed: +-------------------------+-----------+---------------+----------+ | Homepage | Country | Name | Metadata | +-------------------------+-----------+---------------+----------+ | http://savage.net.au/ | Australia | Ron Savage | undef | | https://duckduckgo.com/ | Earth | Mr. S. Engine | empty | +-------------------------+-----------+---------------+----------+ Format: format_internal_boxed: +-------------------+---------------------+----------------------------------------+ | One | Two | Three | +-------------------+---------------------+----------------------------------------+ | Reichwaldstraße | Böhme | ʎ ʏ ʐ ʑ ʒ ʓ ʙ ʚ | | ΔΔΔΔΔΔΔΔΔΔ | Πηληϊάδεω Ἀχιλῆος | A snowman: ☃ | | Two ticks: ✔✔ | undef | <table><tr><td>TBA</td></tr></table> | +-------------------+---------------------+----------------------------------------+ The latter table renders perfectly in FF, but not so in Chrome (today, 2015-01-31). DescriptionOutputs tables in any one of several supported types.Features:
The format of the output is controlled by the "format" parameter to "new()", or by the parameter to the "format([$format])" method, or by the value of the "format" key in the hash passed to "render([%hash])" and "render_as_string(%hash])", and must be one of these imported constants:
See also scripts/synopsis.pl, and the output data/synopsis.log. DistributionsThis module is available as a Unix-style distro (*.tgz).See <http://savage.net.au/Perl-modules/html/installing-a-module.html> for help on unpacking and installing distros. InstallationInstall Text::Table::Manifold as you would any "Perl" module:Run: cpanm Text::Table::Manifold or run: sudo cpan Text::Table::Manifold or unpack the distro, and then either: perl Build.PL ./Build ./Build test sudo ./Build install or: perl Makefile.PL make (or dmake or nmake) make test make install Constructor and Initialization"new()" is called as "my($parser) = Text::Table::Manifold -> new(k1 => v1, k2 => v2, ...)".It returns a new object of type "Text::Table::Manifold". Details of all parameters are explained in the "FAQ". Key-value pairs accepted in the parameter list (see corresponding methods for details [e.g. "data([$arrayref])"]):
MethodsSee the "FAQ" for details of all importable constants mentioned here.And remember, all methods listed here which are parameters to "new([%hash])", are also parameters to both "render([%hash])" and "render_as_string([%hash])". alignment([$arrayref])Here, the [] indicate an optional parameter.Returns the alignment as an arrayref of constants, one per column. There should be one element in $arrayref for each column of data. If the $arrayref is too short, "align_center" is the default for the missing alignments. Obviously, $arrayref might force spaces to be added to one or both sides of a cell value. Alignment applies equally to every cell in the column. This happens before any spaces specified by "padding([$integer])" are added. See the "FAQ#What are the constants for alignment?" for legal values for the alignments (per column). "alignment" is a parameter to "new([%hash])". See "Constructor and Initialization". data([$arrayref])Here, the [] indicate an optional parameter.Returns the data as an arrayref. Each element in this arrayref is an arrayref of one row of data. The structure of $arrayref, if provided, must match the description in the previous line. Rows do not need to have the same number of elements. Use Perl's "undef" or '' (the empty string) for missing values. See "empty([$empty])" and "undef([$undef])" for how '' and "undef" are handled. See "extend_data([$extend])" for how to extend short data rows, or let the code extend auto-extend them. "data" is a parameter to "new([%hash])". See "Constructor and Initialization". empty([$empty])Here, the [] indicate an optional parameter.Returns the option specifying how empty cell values ('') are being dealt with. $empty controls how empty strings in cells are rendered. See the "FAQ#What are the constants for handling cell values which are empty strings?" for legal values for $empty. See also "undef([$undef])". "empty" is a parameter to "new([%hash])". See "Constructor and Initialization". escape([$escape])Here, the [] indicate an optional parameter.Returns the option specifying how HTML entities and URIs are being dealt with. $escape controls how either HTML entities or URIs are rendered. See the "FAQ#What are the constants for escaping HTML entities and URIs?" for legal values for $escape. "escape" is a parameter to "new([%hash])". See "Constructor and Initialization". extend_data([$extend])Here, the [] indicate an optional parameter.Returns the option specifying how short data rows are extended. If the # of elements in a data row is shorter than the longest row, $extend specifies how to extend those short rows. See the "FAQ#What are the constants for extending short rows?" for legal values for $extend. "extend_data" is a parameter to "new([%hash])". See "Constructor and Initialization". extend_footers([$extend])Here, the [] indicate an optional parameter.Returns the option specifying how short footer rows are extended. If the # of elements in a footer row is shorter than the longest row, $extend specifies how to extend those short rows. See the "FAQ#What are the constants for extending short rows?" for legal values for $extend. "extend_footers" is a parameter to "new([%hash])". See "Constructor and Initialization". extend_headers([$extend])Here, the [] indicate an optional parameter.Returns the option specifying how short header rows are extended. If the # of elements in a header row is shorter than the longest row, $extend specifies how to extend those short rows. See the "FAQ#What are the constants for extending short rows?" for legal values for $extend. "extend_headers" is a parameter to "new([%hash])". See "Constructor and Initialization". footers([$arrayref])Here, the [] indicate an optional parameter.Returns the footers as an arrayref of strings. $arrayref, if provided, must be an arrayref of strings. See "extend_footers([$extend])" for how to extend a short footer row, or let the code auto-extend it. "footers" is a parameter to "new([%hash])". See "Constructor and Initialization". format([$format])Here, the [] indicate an optional parameter.Returns the format as a constant (actually an integer). See the "FAQ#What are the constants for formatting?" for legal values for $format. "format" is a parameter to "new([%hash])". See "Constructor and Initialization". format_as_internal_boxed()Called by "render([%hash])".format_as_internal_github()Called by "render([%hash])".format_as_internal_html()Called by "render([%hash])".format_as_html_table()Called by "render([%hash])".format_as_text_csv().Called by "render([%hash])".format_as_text_unicodebox_table()Called by "render([%hash])".headers([$arrayref])Here, the [] indicate an optional parameter.Returns the headers as an arrayref of strings. $arrayref, if provided, must be an arrayref of strings. See "extend_headers([$extend])" for how to extend a short header row, or let the code auto-extend it. "headers" is a parameter to "new([%hash])". See "Constructor and Initialization". include([$include])Here, the [] indicate an optional parameter.Returns the option specifying if header/data/footer rows are included in the output. See the "FAQ#What are the constants for including/excluding rows in the output?" for legal values for $include. "include" is a parameter to "new([%hash])". See "Constructor and Initialization". join([$join])Here, the [] indicate an optional parameter.Returns the string used to join lines in the table when you call "render_as_string([%hash])". $join is the parameter passed to the Perl function "join()" by "render_as_string()". Further, you can use the key "join" in %hash to pass a value directly to "render_as_string([%hash])". new([%hash])The constructor. See "Constructor and Initialization" for details of the parameter list.Note: "render([%hash])" and "render_as_string([%hash])"support the same options as "new()". padding([$integer])Here, the [] indicate an optional parameter.Returns the padding as an integer. Padding is the # of spaces to add to both sides of the cell value after it has been aligned. "padding" is a parameter to "new([%hash])". See "Constructor and Initialization". pass_thru([$hashref])Here, the [] indicate an optional parameter.Returns the hashref previously provided. See "FAQ#What is the format of the $hashref used in the call to pass_thru()?" for details. See scripts/html.table.pl, scripts/internal.table.pl and scripts/text.csv.pl for sample code where it is used in various ways. "pass_thru" is a parameter to "new([%hash])". See "Constructor and Initialization". render([%hash])Here, the [] indicate an optional parameter.Returns an arrayref, where each element is 1 line of the output table. These lines do not have "\n" or any other line terminator added by this module. It's up to you how to handle the output. The simplest thing is to just do: print join("\n", @{$table -> render}), "\n"; Note: "render()" supports the same options as "new([%hash])". "render()" ignores the "join" key in the hash. See also "render_as_string([%hash])". render_as_string([%hash])Here, the [] indicate an optional parameter.Returns the rendered data as a string. "render_as_string" uses the value of $hash{join}, or the result of calling $self -> join, in Perl's "join($join, @$araref)" to join the elements of the arrayref returned by internally calling "render([%hash])". Note: "render_as_string()" supports the same options as "new([%hash])", and passes them all to "render([%hash])". See also "render([%hash])". undef([$undef])Here, the [] indicate an optional parameter.Returns the option specifying how undef cell values are being dealt with. $undef controls how undefs in cells are rendered. See the "FAQ#What are the constants for handling cell values which are undef?" for legal values for $undef. See also "empty([$empty])". "undef" is a parameter to "new([%hash])". See "Constructor and Initialization". widths()Returns an arrayref of the width of each column, after the data is cleaned and rectified, but before it has been aligned or padded.FAQNote: See "TODO" for what has not been implemented yet.How are imported constants used?Firstly, you must import them with:use Text::Table::Manifold ':constants'; Then you can use them in the constructor: my($table) = Text::Table::Manifold -> new(empty => empty_as_text); And/or you can use them in method calls: $table -> format(format_internal_boxed); See scripts/synopsis.pl for various use cases. Note how sample code uses the names of the constants. The integer values listed below are just FYI. What are the constants for alignment?The parameters, one per column, to "alignment([$arrayref])" must be one of the following:
Alignment applies equally to every cell in a column. What are the constants for handling cell values which are empty strings?The parameter to "empty([$empty])" must be one of the following:
See also "undef([$undef])". Warning: This updates the original data! What are the constants for escaping HTML entities and URIs?The parameter to "escape([$escape])" must be one of the following:
Warning: This updates the original data! What are the constants for extending short rows?The parameters to "extend_data([$extend])", "extend_footers([$extend])" and "extend_headers([$extend])", must be one of the following:
See also "empty([$empty])" and "undef([$undef])". Warning: This updates the original data! What are the constants for formatting?The parameter to "format([$format])" must be one of the following:
What are the constants for including/excluding rows in the output?The parameter to "include([$include])" must be one or more of the following:
What is the format of the $hashref used in the call to pass_thru()?It takes these (key => value) pairs:
See html.table.pl, internal.html.pl and text.csv.pl, all in the scripts/ directory. What are the constants for handling cell values which are undef?The parameter to "undef([$undef])" must be one of the following:
See also "empty([$undef])". Warning: This updates the original data! Will you extend the program to support other external renderers?Possibly, but only if the extension matches the spirit of this module, which is roughly: Keep it simple, and provide just enough options but not too many options. IOW, there is no point in passing a huge number of options to an external class when you can use that class directly anyway.I've looked a number of times at PDF::Table, for example, but it is just a little bit too complex. Similarly, Text::ANSITable has too many methods. See also "TODO". How do I run author tests?This runs both standard and author tests:shell> perl Build.PL; ./Build; ./Build authortest TODO
See AlsoTable RenderingAny::RendererData::Formatter::Text Data::Tab Data::Table Data::Tabulate Gapp::TableMap HTML::Table HTML::Tabulate LaTeX::Table PDF::Table PDF::TableX PDF::Report::Table Table::Simple Term::TablePrint Text::ANSITable Text::ASCIITable Text::CSV Text::FormatTable Text::MarkdownTable Text::SimpleTable Text::Table Text::Table::Tiny Text::TabularDisplay Text::Tabulate Text::UnicodeBox Text::UnicodeBox::Table Text::UnicodeTable::Simple Tie::Array::CSV Line BreakingText::FormatText::LineFold Text::NWrap Text::Wrap Text::WrapI18N Unicode::LineBreak. UNICODE LINE BREAKING ALGORITHM <http://unicode.org/reports/tr14/> Machine-Readable Change LogThe file Changes was converted into Changelog.ini by Module::Metadata::Changes.Version NumbersVersion numbers < 1.00 represent development versions. From 1.00 up, they are production versions.Repository<https://github.com/ronsavage/Text-Table-Manifold>SupportBugs should be reported via the CPAN bug tracker at<https://github.com/ronsavage/Text-Table-Manifold/issues> AuthorText::Table::Manifold was written by Ron Savage <ron@savage.net.au> in 2015.Marpa's homepage: <http://savage.net.au/Marpa.html>. My homepage: <http://savage.net.au/>. CopyrightAustralian copyright (c) 2014, Ron Savage.All Programs of mine are 'OSI Certified Open Source Software'; you can redistribute them and/or modify them under the terms of The Perl Artistic License, a copy of which is available at: https://perldoc.perl.org/perlartistic.html.
Visit the GSP FreeBSD Man Page Interface. |