NAME
Docbook::Table -- create Docbook tables from Perl data structures
SYNOPSIS
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);
DESCRIPTION
This module generates Docbook SGML/XML tables from Perl data structures. Its main purpose is to simplify automatic document generation.
Starting your table
use Docbook::Table;
my $t = Docbook::Table->new();
Specifying the title
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");
Specifying the headings
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().
Specifying the body
Accepted data types for the body of the table are:
- Simple hash
-
Used to generate a simple 2-column table.
- List of lists
-
Used to generate multi-column tables.
- Hash of lists
-
Used to generate multi-column tables.
- Hash of hashes and other structures
-
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.
Sorting
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.
Generating the table
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.
AUTHOR
Kirrily Robert <skud@cpan.org>
COPYING
Docbook::Table (c) 2001 Kirrily Robert <skud@cpan.org> This software is distributed under the same licenses as Perl itself.