Debian Codegraph @

upstream/mageia-cauldron/man3pm/Test2::Util::Table.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Test2::Util::Table 3pm"
61 .TH Test2::Util::Table 3pm 2025-06-24 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Test2::Util::Table \- Format a header and rows into a table
68 .SH DESCRIPTION
69 .IX Header "DESCRIPTION"
70 This is used by some failing tests to provide diagnostics about what has gone
71 wrong. This module is able to generic format rows of data into tables.
72 .SH SYNOPSIS
73 .IX Header "SYNOPSIS"
74 .Vb 1
75 \& use Test2::Util::Table qw/table/;
76 \&
77 \& my @table = table(
78 \& max_width => 80,
79 \& collapse => 1, # Do not show empty columns
80 \& header => [ \*(Aqname\*(Aq, \*(Aqage\*(Aq, \*(Aqhair color\*(Aq ],
81 \& rows => [
82 \& [ \*(AqFred Flinstone\*(Aq, 2000000, \*(Aqblack\*(Aq ],
83 \& [ \*(AqWilma Flinstone\*(Aq, 1999995, \*(Aqred\*(Aq ],
84 \& ...,
85 \& ],
86 \& );
87 \&
88 \& # The @table array contains each line of the table, no newlines added.
89 \& say $_ for @table;
90 .Ve
91 .PP
92 This prints a table like this:
93 .PP
94 .Vb 7
95 \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-+
96 \& | name | age | hair color |
97 \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-+
98 \& | Fred Flinstone | 2000000 | black |
99 \& | Wilma Flinstone | 1999995 | red |
100 \& | ... | ... | ... |
101 \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-+
102 .Ve
103 .SH EXPORTS
104 .IX Header "EXPORTS"
105 .ie n .SS "@rows = table(...)"
106 .el .SS "\f(CW@rows\fP = table(...)"
107 .IX Subsection "@rows = table(...)"
108 The function returns a list of lines, lines do not have the newline \f(CW\*(C`\en\*(C'\fR
109 character appended.
110 .PP
111 Options:
112 .IP "header => [ ... ]" 4
113 .IX Item "header => [ ... ]"
114 If you want a header specify it here. This takes an arrayref with each columns
115 heading.
116 .IP "rows => [ [...], [...], ... ]" 4
117 .IX Item "rows => [ [...], [...], ... ]"
118 This should be an arrayref containing an arrayref per row.
119 .ie n .IP "collapse => $bool" 4
120 .el .IP "collapse => \f(CW$bool\fR" 4
121 .IX Item "collapse => $bool"
122 Use this if you want to hide empty columns, that is any column that has no data
123 in any row. Having a header for the column will not effect collapse.
124 .ie n .IP "max_width => $num" 4
125 .el .IP "max_width => \f(CW$num\fR" 4
126 .IX Item "max_width => $num"
127 Set the maximum width of the table, the table may not be this big, but it will
128 be no bigger. If none is specified it will attempt to find the width of your
129 terminal and use that, otherwise it falls back to \f(CW80\fR.
130 .ie n .IP "sanitize => $bool" 4
131 .el .IP "sanitize => \f(CW$bool\fR" 4
132 .IX Item "sanitize => $bool"
133 This will sanitize all the data in the table such that newlines, control
134 characters, and all whitespace except for ASCII 20 \f(CW\*(Aq \*(Aq\fR are replaced with
135 escape sequences. This prevents newlines, tabs, and similar whitespace from
136 disrupting the table.
137 .Sp
138 \&\fBNote:\fR newlines are marked as \*(Aq\en\*(Aq, but a newline is also inserted into the
139 data so that it typically displays in a way that is useful to humans.
140 .Sp
141 Example:
142 .Sp
143 .Vb 1
144 \& my $field = "foo\enbar\enbaz\en";
145 \&
146 \& print join "\en" => table(
147 \& sanitize => 1,
148 \& rows => [
149 \& [$field, \*(Aqcol2\*(Aq ],
150 \& [\*(Aqrow2 col1\*(Aq, \*(Aqrow2 col2\*(Aq]
151 \& ]
152 \& );
153 .Ve
154 .Sp
155 Prints:
156 .Sp
157 .Vb 7
158 \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-+
159 \& | foo\en | col2 |
160 \& | bar\en | |
161 \& | baz\en | |
162 \& | | |
163 \& | row2 col1 | row2 col2 |
164 \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-+
165 .Ve
166 .Sp
167 So it marks the newlines by inserting the escape sequence, but it also shows
168 the data across as many lines as it would normally display.
169 .ie n .IP "mark_tail => $bool" 4
170 .el .IP "mark_tail => \f(CW$bool\fR" 4
171 .IX Item "mark_tail => $bool"
172 This will replace the last whitespace character of any trailing whitespace with
173 its escape sequence. This makes it easier to notice trailing whitespace when
174 comparing values.
175 .ie n .SS "my $cols = \fBterm_size()\fP"
176 .el .SS "my \f(CW$cols\fP = \fBterm_size()\fP"
177 .IX Subsection "my $cols = term_size()"
178 Attempts to find the width in columns (characters) of the current terminal.
179 Returns 80 as a safe bet if it cannot find it another way.
180 .SH "NOTE ON UNICODE/WIDE CHARACTERS"
181 .IX Header "NOTE ON UNICODE/WIDE CHARACTERS"
182 Some unicode characters, such as \f(CW\*(C`婧\*(C'\fR (\f(CW\*(C`U+5A67\*(C'\fR) are wider than others. These
183 will render just fine if you \f(CW\*(C`use utf8;\*(C'\fR as necessary, and
184 Unicode::GCString is installed, however if the module is not installed there
185 will be anomalies in the table:
186 .PP
187 .Vb 7
188 \& +\-\-\-\-\-+\-\-\-\-\-+\-\-\-+
189 \& | a | b | c |
190 \& +\-\-\-\-\-+\-\-\-\-\-+\-\-\-+
191 \& | 婧 | x | y |
192 \& | x | y | z |
193 \& | x | 婧 | z |
194 \& +\-\-\-\-\-+\-\-\-\-\-+\-\-\-+
195 .Ve
196 .SH SOURCE
197 .IX Header "SOURCE"
198 The source code repository for Test2\-Suite can be found at
199 \&\fIhttps://github.com/Test\-More/test\-more/\fR.
200 .SH MAINTAINERS
201 .IX Header "MAINTAINERS"
202 .IP "Chad Granum <[email protected]>" 4
203 .IX Item "Chad Granum <[email protected]>"
204 .SH AUTHORS
205 .IX Header "AUTHORS"
206 .IP "Chad Granum <[email protected]>" 4
207 .IX Item "Chad Granum <[email protected]>"
208 .SH COPYRIGHT
209 .IX Header "COPYRIGHT"
210 Copyright Chad Granum <[email protected]>.
211 .PP
212 This program is free software; you can redistribute it and/or
213 modify it under the same terms as Perl itself.
214 .PP
215 See \fIhttp://dev.perl.org/licenses/\fR