Debian Codegraph @

upstream/debian-unstable/man3/Test2::Util::Table.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "Test2::Util::Table 3perl"
58 .TH Test2::Util::Table 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 Test2::Util::Table \- Format a header and rows into a table
65 .SH DESCRIPTION
66 .IX Header "DESCRIPTION"
67 This is used by some failing tests to provide diagnostics about what has gone
68 wrong. This module is able to generic format rows of data into tables.
69 .SH SYNOPSIS
70 .IX Header "SYNOPSIS"
71 .Vb 1
72 \& use Test2::Util::Table qw/table/;
73 \&
74 \& my @table = table(
75 \& max_width => 80,
76 \& collapse => 1, # Do not show empty columns
77 \& header => [ \*(Aqname\*(Aq, \*(Aqage\*(Aq, \*(Aqhair color\*(Aq ],
78 \& rows => [
79 \& [ \*(AqFred Flinstone\*(Aq, 2000000, \*(Aqblack\*(Aq ],
80 \& [ \*(AqWilma Flinstone\*(Aq, 1999995, \*(Aqred\*(Aq ],
81 \& ...,
82 \& ],
83 \& );
84 \&
85 \& # The @table array contains each line of the table, no newlines added.
86 \& say $_ for @table;
87 .Ve
88 .PP
89 This prints a table like this:
90 .PP
91 .Vb 7
92 \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-+
93 \& | name | age | hair color |
94 \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-+
95 \& | Fred Flinstone | 2000000 | black |
96 \& | Wilma Flinstone | 1999995 | red |
97 \& | ... | ... | ... |
98 \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-+
99 .Ve
100 .SH EXPORTS
101 .IX Header "EXPORTS"
102 .ie n .SS "@rows = table(...)"
103 .el .SS "\f(CW@rows\fP = table(...)"
104 .IX Subsection "@rows = table(...)"
105 The function returns a list of lines, lines do not have the newline \f(CW\*(C`\en\*(C'\fR
106 character appended.
107 .PP
108 Options:
109 .IP "header => [ ... ]" 4
110 .IX Item "header => [ ... ]"
111 If you want a header specify it here. This takes an arrayref with each columns
112 heading.
113 .IP "rows => [ [...], [...], ... ]" 4
114 .IX Item "rows => [ [...], [...], ... ]"
115 This should be an arrayref containing an arrayref per row.
116 .ie n .IP "collapse => $bool" 4
117 .el .IP "collapse => \f(CW$bool\fR" 4
118 .IX Item "collapse => $bool"
119 Use this if you want to hide empty columns, that is any column that has no data
120 in any row. Having a header for the column will not effect collapse.
121 .ie n .IP "max_width => $num" 4
122 .el .IP "max_width => \f(CW$num\fR" 4
123 .IX Item "max_width => $num"
124 Set the maximum width of the table, the table may not be this big, but it will
125 be no bigger. If none is specified it will attempt to find the width of your
126 terminal and use that, otherwise it falls back to \f(CW80\fR.
127 .ie n .IP "sanitize => $bool" 4
128 .el .IP "sanitize => \f(CW$bool\fR" 4
129 .IX Item "sanitize => $bool"
130 This will sanitize all the data in the table such that newlines, control
131 characters, and all whitespace except for ASCII 20 \f(CW\*(Aq \*(Aq\fR are replaced with
132 escape sequences. This prevents newlines, tabs, and similar whitespace from
133 disrupting the table.
134 .Sp
135 \&\fBNote:\fR newlines are marked as '\en', but a newline is also inserted into the
136 data so that it typically displays in a way that is useful to humans.
137 .Sp
138 Example:
139 .Sp
140 .Vb 1
141 \& my $field = "foo\enbar\enbaz\en";
142 \&
143 \& print join "\en" => table(
144 \& sanitize => 1,
145 \& rows => [
146 \& [$field, \*(Aqcol2\*(Aq ],
147 \& [\*(Aqrow2 col1\*(Aq, \*(Aqrow2 col2\*(Aq]
148 \& ]
149 \& );
150 .Ve
151 .Sp
152 Prints:
153 .Sp
154 .Vb 7
155 \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-+
156 \& | foo\en | col2 |
157 \& | bar\en | |
158 \& | baz\en | |
159 \& | | |
160 \& | row2 col1 | row2 col2 |
161 \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-+
162 .Ve
163 .Sp
164 So it marks the newlines by inserting the escape sequence, but it also shows
165 the data across as many lines as it would normally display.
166 .ie n .IP "mark_tail => $bool" 4
167 .el .IP "mark_tail => \f(CW$bool\fR" 4
168 .IX Item "mark_tail => $bool"
169 This will replace the last whitespace character of any trailing whitespace with
170 its escape sequence. This makes it easier to notice trailing whitespace when
171 comparing values.
172 .ie n .SS "my $cols = \fBterm_size()\fP"
173 .el .SS "my \f(CW$cols\fP = \fBterm_size()\fP"
174 .IX Subsection "my $cols = term_size()"
175 Attempts to find the width in columns (characters) of the current terminal.
176 Returns 80 as a safe bet if it cannot find it another way.
177 .SH "NOTE ON UNICODE/WIDE CHARACTERS"
178 .IX Header "NOTE ON UNICODE/WIDE CHARACTERS"
179 Some unicode characters, such as \f(CW\*(C`婧\*(C'\fR (\f(CW\*(C`U+5A67\*(C'\fR) are wider than others. These
180 will render just fine if you \f(CW\*(C`use utf8;\*(C'\fR as necessary, and
181 Unicode::GCString is installed, however if the module is not installed there
182 will be anomalies in the table:
183 .PP
184 .Vb 7
185 \& +\-\-\-\-\-+\-\-\-\-\-+\-\-\-+
186 \& | a | b | c |
187 \& +\-\-\-\-\-+\-\-\-\-\-+\-\-\-+
188 \& | 婧 | x | y |
189 \& | x | y | z |
190 \& | x | 婧 | z |
191 \& +\-\-\-\-\-+\-\-\-\-\-+\-\-\-+
192 .Ve
193 .SH SOURCE
194 .IX Header "SOURCE"
195 The source code repository for Test2\-Suite can be found at
196 \&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR.
197 .SH MAINTAINERS
198 .IX Header "MAINTAINERS"
199 .IP "Chad Granum <[email protected]>" 4
200 .IX Item "Chad Granum <[email protected]>"
201 .SH AUTHORS
202 .IX Header "AUTHORS"
203 .PD 0
204 .IP "Chad Granum <[email protected]>" 4
205 .IX Item "Chad Granum <[email protected]>"
206 .PD
207 .SH COPYRIGHT
208 .IX Header "COPYRIGHT"
209 Copyright 2018 Chad Granum <[email protected]>.
210 .PP
211 This program is free software; you can redistribute it and/or
212 modify it under the same terms as Perl itself.
213 .PP
214 See \fIhttp://dev.perl.org/licenses/\fR