Text::Table::Any(3)

๐Ÿ“ฆ version 0.117, in alpine 3.24

๐Ÿ’– Text::Table::Any ๐Ÿ’–

okay bestie, meet Text::Table::Any(3) โ€” yes, thatโ€™s the manual-page name, and itโ€™s hanging out in the User Contributed Perl Documentation section. This thing is literally a table-generating baddie: you hand it rows, it gives you a text table, and it can flex through a whole lineup of backends. no cap. ๐Ÿ’…


๐ŸŒธ NAME ๐ŸŒธ

Text::Table::Any โ€” generate a text table using one of several backends. periodt โœจ

๐ŸŽ€ VERSION ๐ŸŽ€

This document describes version 0.117 of Text::Table::Any (from Perl distribution Text-Table-Any), released on 2023-11-11. iykyk ๐Ÿ—“๏ธ

โœจ SYNOPSIS โœจ

okay so hereโ€™s the basic slay:

use Text::Table::Any qw/generate_table/;

my $rows = [
    # first element is header row
    ['Distribution', 'Author', 'First Version', 'Latest Version', 'Abstract'],

    # subsequent elements are data rows
    ['ACME-Dzil-Test-daemon', 'DAEMON', '0.001', '0.001', 'Module abstract placeholder text'],
    ['ACME-Dzil-Test-daemon2', 'DAEMON', '0.001', '0.001', 'Module abstract placeholder text'],
    ['Acme-CPANModules-ShellCompleters', 'PERLANCAR', '0.001', '0.001', 'Modules that provide shell tab completion for other commands/scripts'],
    ['Acme-CPANModules-WorkingWithURL', 'PERLANCAR', '0.001', '0.001', 'Working with URL'],
];

print generate_table(rows => $rows);

This will render the table using the default backend Text::Table::Sprintf and print something like:

+----------------------------------+-----------+---------------+----------------+----------------------------------------------------------------------+
| Distribution                     | Author    | First Version | Latest Version | Abstract                                                             |
+----------------------------------+-----------+---------------+----------------+----------------------------------------------------------------------+
| ACME-Dzil-Test-daemon            | DAEMON    | 0.001         | 0.001          | Module abstract placeholder text                                     |
| ACME-Dzil-Test-daemon2           | DAEMON    | 0.001         | 0.001          | Module abstract placeholder text                                     |
| Acme-CPANModules-ShellCompleters | PERLANCAR | 0.001         | 0.001          | Modules that provide shell tab completion for other commands/scripts |
| Acme-CPANModules-WorkingWithURL  | PERLANCAR | 0.001         | 0.001          | Working with URL                                                     |
+----------------------------------+-----------+---------------+----------------+----------------------------------------------------------------------+

To pick another backend:

print generate_table(
    rows => $rows,
    backend => "Text::Table::Org",
);

The result is something like:

| Distribution                     | Author    | First Version | Latest Version | Abstract                                                             |
|----------------------------------+-----------+---------------+----------------+----------------------------------------------------------------------|
| ACME-Dzil-Test-daemon            | DAEMON    | 0.001         | 0.001          | Module abstract placeholder text                                     |
| ACME-Dzil-Test-daemon2           | DAEMON    | 0.001         | 0.001          | Module abstract placeholder text                                     |
| Acme-CPANModules-ShellCompleters | PERLANCAR | 0.001         | 0.001          | Modules that provide shell tab completion for other commands/scripts |
| Acme-CPANModules-WorkingWithURL  | PERLANCAR | 0.001         | 0.001          | Working with URL                                                     |

To specify some other options:

print generate_table(
    rows => $rows,
    header_row => 0,   # default is true
    separate_rows => 1, # default is false
    caption => "Some of the new distributions released in Jan 2022",
    backend => "Text::Table::Org",
);

The result is something like:

#+CAPTION: Some of the new distributions released in Jan 2022
| Distribution                     | Author    | First Version | Latest Version | Abstract                                                             |
|----------------------------------+-----------+---------------+----------------+----------------------------------------------------------------------|
| ACME-Dzil-Test-daemon            | DAEMON    | 0.001         | 0.001          | Module abstract placeholder text                                     |
|----------------------------------+-----------+---------------+----------------+----------------------------------------------------------------------|
| ACME-Dzil-Test-daemon2           | DAEMON    | 0.001         | 0.001          | Module abstract placeholder text                                     |
|----------------------------------+-----------+---------------+----------------+----------------------------------------------------------------------|
| Acme-CPANModules-ShellCompleters | PERLANCAR | 0.001         | 0.001          | Modules that provide shell tab completion for other commands/scripts |
|----------------------------------+-----------+---------------+----------------+----------------------------------------------------------------------|
| Acme-CPANModules-WorkingWithURL  | PERLANCAR | 0.001         | 0.001          | Working with URL                                                     |

To pass backend-specific options:

print generate_table(
    rows => $rows,
    backend => "Text::Table::More",
    backend_opts => {
        border_style => 'ASCII::SingleLineDoubleAfterHeader',
        align => 'right',
        row_attrs => [
            [0, {align=>'middle'}],
        ],
    },
);

The result is something like:

.----------------------------------+-----------+---------------+----------------+----------------------------------------------------------------------.
|           Distribution           |  Author   | First Version | Latest Version |                               Abstract                               |
+==================================+===========+===============+================+======================================================================+
|            ACME-Dzil-Test-daemon |    DAEMON |         0.001 |          0.001 |                                     Module abstract placeholder text |
|           ACME-Dzil-Test-daemon2 |    DAEMON |         0.001 |          0.001 |                                     Module abstract placeholder text |
| Acme-CPANModules-ShellCompleters | PERLANCAR |         0.001 |          0.001 | Modules that provide shell tab completion for other commands/scripts |
|  Acme-CPANModules-WorkingWithURL | PERLANCAR |         0.001 |          0.001 |                                                     Working with URL |
`----------------------------------+-----------+---------------+----------------+----------------------------------------------------------------------'

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

This module gives you one single function, generate_table, and it formats a two-dimensional array of data as a text table using one of several available backends. itโ€™s giving โ€œone function, many fitsโ€ ๐Ÿ’š

The interface is modelled after Text::Table::Tiny, but plot twist: Text::Table::Sprintf is the default backend, and even though Text::Table::Tiny is among the supported backends, it is not required by this module. slay. โœจ

๐Ÿ’… DIFFERENCES WITH TEXT::TABLE::TINY ๐Ÿ’…

  • top_and_tail option from Text::Table::Tiny is not supported โ€” Probably wonโ€™t be supported. You can pass this option to the Text::Table::Tiny backend via the backend_opts option. not me reading the fine print ๐Ÿ™ˆ
  • style option from Text::Table::Tiny is not supported โ€” Wonโ€™t be supported because this is specific to Text::Table::Tiny. If you want custom border styles, here are some alternative backends you can use: Text::ANSITable, Text::Table::TinyBorderStyle, Text::Table::More, Text::UnicodeBox::Table. backend shopping spree ๐ŸŒˆ
  • indent option from Text::Table::Tiny is not supported โ€” Probably wonโ€™t be supported. You can indent a multiline string in Perl using something like:
$rendered_table =~ s/^/  /mg; # indent each line with two spaces
  • compact option from Text::Table::Tiny is not supported โ€” May be supported in the future. future vibes only ๐Ÿ”ฎ

๐Ÿงš VARIABLES ๐Ÿงš

๐ŸŽ€ @BACKENDS

List of supported backends. the whole roster, bestie ๐Ÿ‘‘

๐Ÿ”ฎ %BACKEND_FEATURES

List of features supported by each backend. Hash key is backend name, e.g. "Text::Table::Sprintf". Hash value is a hashref containing feature name as hashref key and a boolean value or other value as hashref value to describe the support of that feature by that backend. feature detective era ๐Ÿ•ต๏ธโ€โ™€๏ธ

๐Ÿซถ FUNCTIONS ๐Ÿซถ

๐Ÿงธ table

An old name for generate_table function (generate_table() was not available in Text::Table::Tiny < 0.04). This name is not available for export. vintage name, no export ๐Ÿ•ฐ๏ธ

๐Ÿ‘‘ generate_table

Exportable. come get your function โœจ

Usage:

table(%params) => str

Except for the backend parameter, the parameters will mostly be passed to the backend, sometimes slightly modified if necessary to achieve the desired effect. If a parameter is not supported by a backend, then it will not be passed to the backend. selective passing, iconic behavior ๐Ÿ’™

Known parameters:

  • backend โ€” Optional. Str, default Text::Table::Sprintf. Pick a backend module. Supported backends:
    • Term::Table
    • Term::TablePrint
    • Text::ANSITable
    • Text::ASCIITable
    • Text::FormatTable
    • Text::MarkdownTable
    • Text::Table
    • Text::Table::ASV
    • Text::Table::CSV
    • Text::Table::HTML
    • Text::Table::HTML::DataTables
    • Text::Table::LTSV
    • Text::Table::Manifold
    • Text::Table::More
    • Text::Table::Org
    • Text::Table::Paragraph
    • Text::Table::Sprintf
    • Text::Table::TSV
    • Text::Table::TickitWidget
    • Text::Table::Tiny
    • Text::Table::TinyBorderStyle
    • Text::Table::TinyColor
    • Text::Table::TinyColorWide
    • Text::Table::TinyWide
    • Text::Table::XLSX
    • Text::TabularDisplay
    • Text::UnicodeBox::Table

Support matrix for each backend:

Okay so the backend-support matrix is a whole mood, and since tables are banned in this chat weโ€™re doing it as bullets with every single cell intact, no cap. Fields are exactly: backend, align, align_note, backend_opts, backend_opts_note, caption, header_row, rows, separate_rows.

  • Term::Table โ€” align: 0; align_note: (empty); backend_opts: (empty); backend_opts_note: (empty); caption: 0; header_row: 1; rows: 1; separate_rows: 0.
  • Term::TablePrint โ€” align: 0; align_note: (empty); backend_opts: (empty); backend_opts_note: (empty); caption: 0; header_row: 1; rows: 1; separate_rows: 0.
  • Text::ANSITable โ€” align: 1; align_note: (empty); backend_opts: (empty); backend_opts_note: (empty); caption: 0; header_row: 1; rows: 1; separate_rows: 1.
  • Text::ASCIITable โ€” align: 1; align_note: (empty); backend_opts: (empty); backend_opts_note: (empty); caption: 0; header_row: 1; rows: 1; separate_rows: 0.
  • Text::FormatTable โ€” align: 1; align_note: c(enter) alignment is not supported, will fallback to l(eft); backend_opts: (empty); backend_opts_note: (empty); caption: 0; header_row: 0; rows: 1; separate_rows: 0.
  • Text::MarkdownTable โ€” align: 0; align_note: (empty); backend_opts: (empty); backend_opts_note: (empty); caption: 0; header_row: 1; rows: 1; separate_rows: 0.
  • Text::Table โ€” align: 1; align_note: (empty); backend_opts: (empty); backend_opts_note: (empty); caption: 0; header_row: 0; rows: 1; separate_rows: 0.
  • Text::Table::ASV โ€” align: 0; align_note: (empty); backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 1; rows: 1; separate_rows: 0.
  • Text::Table::CSV โ€” align: 0; align_note: (empty); backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 1; rows: 1; separate_rows: 0.
  • Text::Table::HTML โ€” align: 0; align_note: TODO, backend does not support yet, parameter already passed; backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 1; header_row: 1; rows: 1; separate_rows: 0.
  • Text::Table::HTML::DataTables โ€” align: 0; align_note: TODO, backend does not support yet, parameter already passed; backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 1; header_row: 1; rows: 1; separate_rows: 0.
  • Text::Table::LTSV โ€” align: 0; align_note: (empty); backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 0; rows: 1; separate_rows: 0.
  • Text::Table::Manifold โ€” align: 1; align_note: (empty); backend_opts: (empty); backend_opts_note: (empty); caption: 0; header_row: 1; rows: 1; separate_rows: 0.
  • Text::Table::More โ€” align: 1; align_note: (empty); backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 1; rows: 1; separate_rows: 1.
  • Text::Table::Org โ€” align: 0; align_note: (empty); backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 1; header_row: 1; rows: 1; separate_rows: 1.
  • Text::Table::Paragraph โ€” align: 0; align_note: (empty); backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 1; rows: 1; separate_rows: 0.
  • Text::Table::Sprintf โ€” align: 0; align_note: (empty); backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 1; rows: 1; separate_rows: 1.
  • Text::Table::TSV โ€” align: 0; align_note: (empty); backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 0; rows: 1; separate_rows: 0.
  • Text::Table::TickitWidget โ€” align: 0; align_note: (empty); backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 1; rows: 1; separate_rows: 0.
  • Text::Table::Tiny โ€” align: 1; align_note: (empty); backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 1; rows: 1; separate_rows: 1.
  • Text::Table::TinyBorderStyle โ€” align: 0; align_note: TODO, backend does not support yet, parameter already passed; backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 1; rows: 1; separate_rows: 1.
  • Text::Table::TinyColor โ€” align: 0; align_note: TODO, backend does not support yet, parameter already passed; backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 1; rows: 1; separate_rows: 1.
  • Text::Table::TinyColorWide โ€” align: 0; align_note: TODO, backend does not support yet, parameter already passed; backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 1; rows: 1; separate_rows: 1.
  • Text::Table::TinyWide โ€” align: 0; align_note: TODO, backend does not support yet, parameter already passed; backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 1; rows: 1; separate_rows: 1.
  • Text::Table::XLSX โ€” align: 0; align_note: (empty); backend_opts: 1; backend_opts_note: Backend-specific options (backend_opts) will be passed to table() or generate_table() directly; caption: 0; header_row: 1; rows: 1; separate_rows: 0.
  • Text::TabularDisplay โ€” align: 0; align_note: (empty); backend_opts: (empty); backend_opts_note: (empty); caption: 0; header_row: 0; rows: 1; separate_rows: 0.
  • Text::UnicodeBox::Table โ€” align: 0; align_note: TODO: backend supports left/right; backend_opts: (empty); backend_opts_note: (empty); caption: 0; header_row: 1; rows: 1; separate_rows: 0.

Now the option tea, bestie:

  • rows โ€” Required. Itโ€™s an Aoaos (array of array-of-scalars). Each element in the array is a row of data, where each row is an array reference. Periodt.
  • header_row โ€” Optional. Bool, default is true. If you give it a true value, the first row in the data gets interpreted as a header row and separated visually from the rest of the table (e.g. with a ruled line). But some backends wonโ€™t display differently.
  • separate_rows โ€” Boolean. Optional. Default is false. If set to true, it will draw a separator line after each data row.

Not all backends support this.

  • caption โ€” Optional. Str. Caption of the table.
  • align โ€” Optional. Array of Str or Str.

This takes an array ref with one entry per column, to specify the alignment of that column. Legal values are 'l', 'c', and 'r' (for left, center, and right, respectively). You can also specify a single alignment for all columns.

Not all backends support this. For example, Text::Table::Sprintf prior to 0.007 does not support this at all. Starting from 0.007, only support left and right alignment.

Note that some backends like Text::ANSITable and Text::Table::More support per-row or per-cell or even conditional alignment. Some backends like Text::ASCIITable and Text::Table can also align beyond just l(eft), c(enter), r(right), e.g. "justify" or align on a decimal point. To do more fine-grained alignment setting, you can use the "backend_opts" parameter.

  • backend_opts โ€” Optional. Hashref. Pass backend-specific options to the backend module. Not all backend modules support this, but all backend modules that have interface following "Text::Table::Tiny" should support this. Also note that as the list of common options is expanded, a previously backend-specific option might be available later as a common option.

๐Ÿงš backends ๐Ÿงš

Return list of supported backends. You can also get the list from the @BACKENDS package variable.

๐ŸŒธ HOMEPAGE ๐ŸŒธ

Please visit the projectโ€™s homepage at https://metacpan.org/release/Text-Table-Any.

๐Ÿฆ‹ SOURCE ๐Ÿฆ‹

Source repository is at https://github.com/perlancar/perl-Text-Table-Any.

๐ŸŽ€ SEE ALSO ๐ŸŽ€

Acme::CPANModules::TextTable

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

perlancar <perlancar@cpan.org>

๐Ÿ’– CONTRIBUTING ๐Ÿ’–

To contribute, you can send patches by email/via RT, or send pull requests on GitHub.

Most of the time, you donโ€™t need to build the distribution yourself. You can simply modify the code, then test via:

% prove -l

If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.

okay legal era, bestie, but make it cute โ€” here's the receipts:

This software is copyright (c) 2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015 by perlancar <perlancar@cpan.org>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. ๐Ÿซถ

tl;dr: it's free, it's Perl-licensed, go off โ€” just don't come for perlancar. ๐Ÿ’…

๐Ÿ› BUGS ๐Ÿ›

found a lil glitch? a feature you're obsessed with and simply need? Please report any bugs or feature requests on the bugtracker website:

https://rt.cpan.org/Public/Dist/Display.html?Name=Text-Table-Any

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. fr fr, this is not optional-optional โ€” a failing test is the whole vibe check and it makes the fix like 100x easier. ๐Ÿ˜ญโœจ

no test file = the maintainer is just squinting at your description like ๐Ÿ‘๏ธ๐Ÿ‘„๐Ÿ‘๏ธ โ€” give them the receipts!

and that's the whole page, bestie! ๐ŸŽ€ you made it to the end, which is honestly iconic of you.

this was Text::Table::Any(3) โ€” footer says perl v5.42.2, dated 2026-02-15. Screenshot it, cite it, frame it. ๐Ÿ’œ

go forth and make tables that slay. ๐Ÿ’…โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from