TEST2::UTIL::TABLE(3pm)
π
Test2::Util::Table β the Test2::Util::Table(3pm) glow-up
Okay so bestie, welcome to Test2::Util::Table(3pm) β the little Perl module from the Perl Programmers Reference Guide that literally just formats your header + rows into a pretty little table π
β¨ NAME β¨
Test2::Util::Table β Format a header and rows into a table. That's it, that's the whole vibe π
π¦ DESCRIPTION π¦
So here's the tea: this module gets used by some failing tests to give you diagnostics about what actually went wrong π Like, when a test flops, this thing is the one pulling up with receipts. It's able to generic format rows of data into tables β no cap, that's literally what it does β¨
πΈ SYNOPSIS πΈ
use Test2::Util::Table qw/table/;
my @table = table(
max_width => 80,
collapse => 1, # Do not show empty columns
header => [ 'name', 'age', 'hair color' ],
rows => [
[ 'Fred Flinstone', 2000000, 'black' ],
[ 'Wilma Flinstone', 1999995, 'red' ],
...,
],
);
# The @table array contains each line of the table, no newlines added.
say $_ for @table;
And this prints a table like this π
+-----------------+---------+------------+
| name | age | hair color |
+-----------------+---------+------------+
| Fred Flinstone | 2000000 | black |
| Wilma Flinstone | 1999995 | red |
| ... | ... | ... |
+-----------------+---------+------------+
Obsessed. Iconic. The alignment? Immaculate π€β¨
π EXPORTS π
π @rows = table(...)
The function returns a list of lines, and those lines do not have the newline "\n" character appended. Clean lines only, no trailing baggage π
Here come the options, bestie β pay attention, there's a lot of them:
header => [ ... ]
If you want a header, specify it here. This takes an arrayref with each column's heading. It's giving... labels π
rows => [ [...], [...], ... ]
This should be an arrayref containing an arrayref per row. Row inside a row, inception style π
collapse => $bool
Use this if you want to hide empty columns β that is, any column that has no data in any row. And heads up: having a header for the column will not effect collapse. So the header doesn't get a say in it, periodt.
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'll attempt to find the width of your terminal and use that β otherwise it falls back to 80. Safety net energy π«Ά
sanitize => $bool
Okay this one's important π₯ This will sanitize all the data in the table such that newlines, control characters, and all whitespace except for ASCII 20 ' ' are replaced with escape sequences. This prevents newlines, tabs, and similar whitespace from disrupting the table. We love a tidy table π
Note: newlines are marked as '\n', but a newline is also inserted into the data so that it typically displays in a way that's useful to humans π
Example, because examples ate:
my $field = "foo\nbar\nbaz\n";
print join "\n" => table(
sanitize => 1,
rows => [
[$field, 'col2' ],
['row2 col1', 'row2 col2']
]
);
Prints:
+-----------------+-----------+
| foo\n | col2 |
| bar\n | |
| baz\n | |
| | |
| row2 col1 | row2 col2 |
+-----------------+-----------+
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. Both things at once β multitasking icon π
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. Trailing whitespace is sneaky and must be exposed π€
β 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. Lowkey the most reliable friend in the group chat π«Ά
π§ NOTE ON UNICODE/WIDE CHARACTERS π§
Some unicode characters, such as "ε©§" ("U+5A67") are wider than others. These will render just fine if you use utf8; as necessary, and Unicode::GCString is installed β however if the module is not installed there will be anomalies in the table ππ
+-----+-----+---+
| a | b | c |
+-----+-----+---+
| ε©§ | x | y |
| x | y | z |
| x | ε©§ | z |
+-----+-----+---+
See how cursed that looks? Yeah. Install the module, bestie π
π₯ SOURCE π₯
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. Go star it, iykyk β
π MAINTAINERS π
Chad Granum <exodist@cpan.org>
π AUTHORS π
Chad Granum <exodist@cpan.org>
π COPYRIGHT π
Copyright Chad Granum <exodist@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
That's the whole page, bestie, no crumbs left π This was perl v5.42.3, dated 2026-11-03, and yes β the page you just read is literally called Test2::Util::Table(3pm). Slay π
β¨
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms