HTML-QuickTable

 view release on metacpan or  search on metacpan

lib/HTML/QuickTable.pm  view on Meta::CPAN


=head1 FUNCTIONS

=head2 new(opt => val, opt => val)

The C<new()> function takes a list of options and returns a C<$qt>
object, which can then be used to C<render()> different data. The
C<new()> function has a flexible options-parsing mechanism that 
allows you to specify settings to pretty much any element of the
table.

Options include:

=over

=item header => 1 | 0

If set to C<1>, a basic C<CGI> header and leading C<HTML> is printed
out. Useful if you're really looking for quick and dirty. Defaults
to C<0>.

=item htmlize => 1 | 0

If set to 1, then all values will be run through a simple filter that
creates links for things that look like email addresses or websites.
Also, C<*word*> will be changed to C<< <b>word</b> >>, and C<_word_>
will be changed to C<< <i>word</i> >>.

=item labels => 1 | 0 | LTRB

If set to 1, then the first row of the data is used as the labels
of the data columns, and is placed in C<< <th> >> tags. For example,
if we assume our above data structure, and said:

    my $qt = HTML::QuickTable->new(... labels => 1);

    unshift @data, ['User', 'Name', 'Ext', 'Email'];

    print $qt->render(\@data);

You would get something like this:

    <table>
    <tr><th>User</th><th>Name</th><th>Ext</th><th>Email</th></tr>
    <tr><td>nwiger</td><td>Nathan Wiger</td><td>x43264</td><td>nate@wiger.org</td></tr>
    <tr><td>jbobson</td><td>Jim Bobson</td><td>x92811</td><td>jim@bobson.com</td></tr>
    </table>

Since the labels are placed in C<< <th> >> tags, you can then use
the extra C<HTML> options described below to alter the way that the
labels look. 

You can also set this to a string that includes the characters
L, T, R, and B, to specify that C<< <th> >> tags should be created
for the Left, Top, Right, and Bottom rows and columns. So for example:

    labels => 'LT'

Would alter the table so that both the first row AND first column
had C<< <th> >> instead of C<< <td> >> elements. This is useful
for creating tables that have two axes, such as calendars.

=item null => $string

If set, then null (undef) fields will be set to that string instead.
This is useful if pulling a bunch of records out of a database and
not wanting to get blank table spaces everywhere there's a null field.
For example:

    my $qt = HTML::QuickTable->new(null => '-');
    my $all_arrayref = $sth->fetchall_arrayref;
    print $qt->render($all_arrayref);

By default null table elements are left blank.

=item nulltags => \%hash

In addition to just changing the string used to represent null data,
you may want to change the look of it as well. These tags will become
attributes to the C<< <td> >> element holding the null field. So, 
settings like this:

    null => 'N/A',
    nulltags => {bgcolor => 'gray'},

Would result in an element like the following for null fields:

    <td bgcolor="gray">N/A<td>

Make sense?

=item stylesheet => 1 | '/path/to/style.css'

If set, then any font settings are ignored and instead all table
elements are wrapped with a C<class=> attribute. The class name
is whatever C<styleclass> is set to (see below). See also the
C<useid> option to generate C<id> tags in an intelligent way.

=item styleclass => $string | \@array

This used as a style class to use if the above setting is used.
If set to a string, it is passed directly to the C<class> tag.
If set to an arrayref, then those styles are alternated between
on a row-by-row (C<tr>) basis. For example:

    styleclass => [qw(one two)]

Would yield C<XHTML> similar to:

    <table class="one">
      <tr class="one">
        <td class="one">a</td>
        <td class="one">b</td>
        <td class="one">c</td>
        <td class="one">d</td>
      </tr>
      <tr class="two">
        <td class="two">e</td>
        <td class="two">f</td>
        <td class="two">g</td>
        <td class="two">h</td>



( run in 1.718 second using v1.01-cache-2.11-cpan-13bb782fe5a )