Mini Shell
Direktori : /usr/local/share/man/man3/ |
|
Current File : //usr/local/share/man/man3/Template::Plugin::Table.3pm |
.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Template::Plugin::Table 3"
.TH Template::Plugin::Table 3 "2024-06-21" "perl v5.32.1" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Template::Plugin::Table \- Plugin to present data in a table
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& [% USE table(list, rows=n, cols=n, overlap=n, pad=0) %]
\&
\& [% FOREACH item IN table.row(n) %]
\& [% item %]
\& [% END %]
\&
\& [% FOREACH item IN table.col(n) %]
\& [% item %]
\& [% END %]
\&
\& [% FOREACH row IN table.rows %]
\& [% FOREACH item IN row %]
\& [% item %]
\& [% END %]
\& [% END %]
\&
\& [% FOREACH col IN table.cols %]
\& [% col.first %] \- [% col.last %] ([% col.size %] entries)
\& [% END %]
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The \f(CW\*(C`Table\*(C'\fR plugin allows you to format a list of data items into a
virtual table. When you create a \f(CW\*(C`Table\*(C'\fR plugin via the \f(CW\*(C`USE\*(C'\fR directive,
simply pass a list reference as the first parameter and then specify
a fixed number of rows or columns.
.PP
.Vb 2
\& [% USE Table(list, rows=5) %]
\& [% USE table(list, cols=5) %]
.Ve
.PP
The \f(CW\*(C`Table\*(C'\fR plugin name can also be specified in lower case as shown
in the second example above. You can also specify an alternative variable
name for the plugin as per regular Template Toolkit syntax.
.PP
.Vb 1
\& [% USE mydata = table(list, rows=5) %]
.Ve
.PP
The plugin then presents a table based view on the data set. The data
isn't actually reorganised in any way but is available via the \f(CW\*(C`row()\*(C'\fR,
\&\f(CW\*(C`col()\*(C'\fR, \f(CW\*(C`rows()\*(C'\fR and \f(CW\*(C`cols()\*(C'\fR as if formatted into a simple two dimensional
table of \f(CW\*(C`n\*(C'\fR rows x \f(CW\*(C`n\*(C'\fR columns.
.PP
So if we had a sample \f(CW\*(C`alphabet\*(C'\fR list contained the letters '\f(CW\*(C`a\*(C'\fR' to '\f(CW\*(C`z\*(C'\fR',
the above \f(CW\*(C`USE\*(C'\fR directives would create plugins that represented the following
views of the alphabet.
.PP
.Vb 1
\& [% USE table(alphabet, ... %]
\&
\& rows=5 cols=5
\& a f k p u z a g m s y
\& b g l q v b h n t z
\& c h m r w c i o u
\& d i n s x d j p v
\& e j o t y e k q w
\& f l r x
.Ve
.PP
We can request a particular row or column using the \f(CW\*(C`row()\*(C'\fR and \f(CW\*(C`col()\*(C'\fR
methods.
.PP
.Vb 4
\& [% USE table(alphabet, rows=5) %]
\& [% FOREACH item = table.row(0) %]
\& # [% item %] set to each of [ a f k p u z ] in turn
\& [% END %]
\&
\& [% FOREACH item = table.col(2) %]
\& # [% item %] set to each of [ m n o p q r ] in turn
\& [% END %]
.Ve
.PP
Data in rows is returned from left to right, columns from top to
bottom. The first row/column is 0. By default, rows or columns that
contain empty values will be padded with the undefined value to fill
it to the same size as all other rows or columns.
.PP
For example, the last row (row 4) in the first example would contain the
values \f(CW\*(C`[ e j o t y undef ]\*(C'\fR. The Template Toolkit will safely accept these
undefined values and print a empty string. You can also use the \s-1IF\s0 directive
to test if the value is set.
.PP
.Vb 5
\& [% FOREACH item = table.row(4) %]
\& [% IF item %]
\& Item: [% item %]
\& [% END %]
\& [% END %]
.Ve
.PP
You can explicitly disable the \f(CW\*(C`pad\*(C'\fR option when creating the plugin to
returned shortened rows/columns where the data is empty.
.PP
.Vb 4
\& [% USE table(alphabet, cols=5, pad=0) %]
\& [% FOREACH item = table.col(4) %]
\& # [% item %] set to each of \*(Aqy z\*(Aq
\& [% END %]
.Ve
.PP
The \f(CW\*(C`rows()\*(C'\fR method returns all rows/columns in the table as a reference
to a list of rows (themselves list references). The \f(CW\*(C`row()\*(C'\fR methods
when called without any arguments calls \f(CW\*(C`rows()\*(C'\fR to return all rows in
the table.
.PP
Ditto for \f(CW\*(C`cols()\*(C'\fR and \f(CW\*(C`col()\*(C'\fR.
.PP
.Vb 6
\& [% USE table(alphabet, cols=5) %]
\& [% FOREACH row = table.rows %]
\& [% FOREACH item = row %]
\& [% item %]
\& [% END %]
\& [% END %]
.Ve
.PP
The Template Toolkit provides the \f(CW\*(C`first\*(C'\fR, \f(CW\*(C`last\*(C'\fR and \f(CW\*(C`size\*(C'\fR virtual
methods that can be called on list references to return the first/last entry
or the number of entries in a list. The following example shows how we might
use this to provide an alphabetical index split into 3 even parts.
.PP
.Vb 4
\& [% USE table(alphabet, cols=3, pad=0) %]
\& [% FOREACH group = table.col %]
\& [ [% group.first %] \- [% group.last %] ([% group.size %] letters) ]
\& [% END %]
.Ve
.PP
This produces the following output:
.PP
.Vb 3
\& [ a \- i (9 letters) ]
\& [ j \- r (9 letters) ]
\& [ s \- z (8 letters) ]
.Ve
.PP
We can also use the general purpose \f(CW\*(C`join\*(C'\fR virtual method which joins
the items of the list using the connecting string specified.
.PP
.Vb 4
\& [% USE table(alphabet, cols=5) %]
\& [% FOREACH row = table.rows %]
\& [% row.join(\*(Aq \- \*(Aq) %]
\& [% END %]
.Ve
.PP
Data in the table is ordered downwards rather than across but can easily
be transformed on output. For example, to format our data in 5 columns
with data ordered across rather than down, we specify \f(CW\*(C`rows=5\*(C'\fR to order
the data as such:
.PP
.Vb 5
\& a f . .
\& b g .
\& c h
\& d i
\& e j
.Ve
.PP
and then iterate down through each column (a\-e, f\-j, etc.) printing
the data across.
.PP
.Vb 4
\& a b c d e
\& f g h i j
\& . .
\& .
.Ve
.PP
Example code to do so would be much like the following:
.PP
.Vb 6
\& [% USE table(alphabet, rows=3) %]
\& [% FOREACH cols = table.cols %]
\& [% FOREACH item = cols %]
\& [% item %]
\& [% END %]
\& [% END %]
.Ve
.PP
Output:
.PP
.Vb 5
\& a b c
\& d e f
\& g h i
\& j . .
\& .
.Ve
.PP
In addition to a list reference, the \f(CW\*(C`Table\*(C'\fR plugin constructor may be passed
a reference to a Template::Iterator object or subclass thereof. The
Template::Iterator \fBget_all()\fR method is
first called on the iterator to return all remaining items. These are then
available via the usual Table interface.
.PP
.Vb 1
\& [% USE DBI(dsn,user,pass) \-%]
\&
\& # query() returns an iterator
\& [% results = DBI.query(\*(AqSELECT * FROM alphabet ORDER BY letter\*(Aq) %]
\&
\& # pass into Table plugin
\& [% USE table(results, rows=8 overlap=1 pad=0) \-%]
\&
\& [% FOREACH row = table.cols \-%]
\& [% row.first.letter %] \- [% row.last.letter %]:
\& [% row.join(\*(Aq, \*(Aq) %]
\& [% END %]
.Ve
.SH "AUTHOR"
.IX Header "AUTHOR"
Andy Wardley <abw@wardley.org> <http://wardley.org/>
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright (C) 1996\-2022 Andy Wardley. All Rights Reserved.
.PP
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Template::Plugin
Zerion Mini Shell 1.0