Docbook::Table -- create Docbook tables from Perl data structures
use Docbook::Table; my $t = Docbook::Table->new(); $t->title("Pet names"); $t->headings("Pet type", "Pet name"); my %pets = ( dog => "Rover", cat => "Garfield", bird => "Tweetie" ); $t->body(\%pets); $t->generate; $t->sort(\&backwards);
This module generates Docbook SGML/XML tables from Perl data structures. Its main purpose is to simplify automatic document generation.
use Docbook::Table; my $t = Docbook::Table->new();
Docbook tables must have a title. You can set the title by passing a string to the title() method.
$t->title("This is the title");
Simply pass a list of headings to the headings() method.
$t->headings(@headings);
Note that the number of columns (a required attribute of the tgroup element) is generated by counting the number of elements in the list passed to headings().
tgroup
Accepted data types for the body of the table are:
Used to generate a simple 2-column table.
Used to generate multi-column tables.
Not supported (yet).
All data structures for the body should be passed by reference to the body() method.
$t->body(\%hash); $t->body(\@list);
If you pass it the wrong sort of thing, it will emit a warning and return undef.
By default, hashes are sorted asciibetically by key, and lists are left in their original order. If you wish to specify a different sort order, pass a subroutine reference to the sort() method.
$t->sort(\&backwards); $t->sort( sub { $b cmp $a } );
If you pass it anything other than a subroutine reference, it will emit a warning and return undef.
The generate() method actually generates the table for you and returns it as a string. It will emit warnings and return undef if you haven't specified a title, headings and a body.
Kirrily Robert <skud@cpan.org>
Docbook::Table (c) 2001 Kirrily Robert <skud@cpan.org> This software is distributed under the same licenses as Perl itself.
YAML
To install Docbook::Table, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Docbook::Table
CPAN shell
perl -MCPAN -e shell install Docbook::Table
For more information on module installation, please visit the detailed CPAN module installation guide.