.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.13)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.ie \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.el \{\
. de IX
..
.\}
.\" ========================================================================
.\"
.IX Title "Test2::Util::Table 3"
.TH Test2::Util::Table 3 "2019-05-18" "perl v5.10.1" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Test2::Util::Table \- Format a header and rows into a table
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This is used by some failing tests to provide diagnostics about what has gone
wrong. This module is able to generic format rows of data into tables.
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Test2::Util::Table qw/table/;
\&
\& my @table = table(
\& max_width => 80,
\& collapse => 1, # Do not show empty columns
\& header => [ \*(Aqname\*(Aq, \*(Aqage\*(Aq, \*(Aqhair color\*(Aq ],
\& rows => [
\& [ \*(AqFred Flinstone\*(Aq, 2000000, \*(Aqblack\*(Aq ],
\& [ \*(AqWilma Flinstone\*(Aq, 1999995, \*(Aqred\*(Aq ],
\& ...,
\& ],
\& );
\&
\& # The @table array contains each line of the table, no newlines added.
\& say $_ for @table;
.Ve
.PP
This prints a table like this:
.PP
.Vb 7
\& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-+
\& | name | age | hair color |
\& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-+
\& | Fred Flinstone | 2000000 | black |
\& | Wilma Flinstone | 1999995 | red |
\& | ... | ... | ... |
\& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-+
.Ve
.SH "EXPORTS"
.IX Header "EXPORTS"
.ie n .SS "@rows = table(...)"
.el .SS "\f(CW@rows\fP = table(...)"
.IX Subsection "@rows = table(...)"
The function returns a list of lines, lines do not have the newline \f(CW\*(C`\en\*(C'\fR
character appended.
.PP
Options:
.IP "header => [ ... ]" 4
.IX Item "header => [ ... ]"
If you want a header specify it here. This takes an arrayref with each columns
heading.
.IP "rows => [ [...], [...], ... ]" 4
.IX Item "rows => [ [...], [...], ... ]"
This should be an arrayref containing an arrayref per row.
.ie n .IP "collapse => $bool" 4
.el .IP "collapse => \f(CW$bool\fR" 4
.IX Item "collapse => $bool"
Use this if you want to hide empty columns, that is any column that has no data
in any row. Having a header for the column will not effect collapse.
.ie n .IP "max_width => $num" 4
.el .IP "max_width => \f(CW$num\fR" 4
.IX Item "max_width => $num"
Set the maximum width of the table, the table may not be this big, but it will
be no bigger. If none is specified it will attempt to find the width of your
terminal and use that, otherwise it falls back to \f(CW80\fR.
.ie n .IP "sanitize => $bool" 4
.el .IP "sanitize => \f(CW$bool\fR" 4
.IX Item "sanitize => $bool"
This will sanitize all the data in the table such that newlines, control
characters, and all whitespace except for \s-1ASCII\s0 20 \f(CW\*(Aq \*(Aq\fR are replaced with
escape sequences. This prevents newlines, tabs, and similar whitespace from
disrupting the table.
.Sp
\&\fBNote:\fR newlines are marked as '\en', but a newline is also inserted into the
data so that it typically displays in a way that is useful to humans.
.Sp
Example:
.Sp
.Vb 1
\& my $field = "foo\enbar\enbaz\en";
\&
\& print join "\en" => table(
\& sanitize => 1,
\& rows => [
\& [$field, \*(Aqcol2\*(Aq ],
\& [\*(Aqrow2 col1\*(Aq, \*(Aqrow2 col2\*(Aq]
\& ]
\& );
.Ve
.Sp
Prints:
.Sp
.Vb 7
\& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-+
\& | foo\en | col2 |
\& | bar\en | |
\& | baz\en | |
\& | | |
\& | row2 col1 | row2 col2 |
\& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-+
.Ve
.Sp
So it marks the newlines by inserting the escape sequence, but it also shows
the data across as many lines as it would normally display.
.ie n .IP "mark_tail => $bool" 4
.el .IP "mark_tail => \f(CW$bool\fR" 4
.IX Item "mark_tail => $bool"
This will replace the last whitespace character of any trailing whitespace with
its escape sequence. This makes it easier to notice trailing whitespace when
comparing values.
.ie n .SS "my $cols = \fIterm_size()\fP"
.el .SS "my \f(CW$cols\fP = \fIterm_size()\fP"
.IX Subsection "my $cols = term_size()"
Attempts to find the width in columns (characters) of the current terminal.
Returns 80 as a safe bet if it cannot find it another way.
.SH "NOTE ON UNICODE/WIDE CHARACTERS"
.IX Header "NOTE ON UNICODE/WIDE CHARACTERS"
Some unicode characters, such as \f(CW\*(C`婧\*(C'\fR (\f(CW\*(C`U+5A67\*(C'\fR) are wider than others. These
will render just fine if you \f(CW\*(C`use utf8;\*(C'\fR as necessary, and
Unicode::GCString is installed, however if the module is not installed there
will be anomalies in the table:
.PP
.Vb 7
\& +\-\-\-\-\-+\-\-\-\-\-+\-\-\-+
\& | a | b | c |
\& +\-\-\-\-\-+\-\-\-\-\-+\-\-\-+
\& | 婧 | x | y |
\& | x | y | z |
\& | x | 婧 | z |
\& +\-\-\-\-\-+\-\-\-\-\-+\-\-\-+
.Ve
.SH "SOURCE"
.IX Header "SOURCE"
The source code repository for Test2\-Suite can be found at
\&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR.
.SH "MAINTAINERS"
.IX Header "MAINTAINERS"
.IP "Chad Granum <exodist@cpan.org>" 4
.IX Item "Chad Granum <exodist@cpan.org>"
.SH "AUTHORS"
.IX Header "AUTHORS"
.PD 0
.IP "Chad Granum <exodist@cpan.org>" 4
.IX Item "Chad Granum <exodist@cpan.org>"
.PD
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright 2018 Chad Granum <exodist@cpan.org>.
.PP
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
.PP
See \fIhttp://dev.perl.org/licenses/\fR
Copyright 2K16 - 2K18 Indonesian Hacker Rulez