Template::Manual::Plugins - Standard plugins
[% USE autoformat(left=10, right=20) %]
[% autoformat(mytext) %] # call autoformat sub
[% mytext FILTER autoformat %] # or use autoformat filter
The Text::Autoformat module is available from CPAN:
http://www.cpan.org/modules/by-module/Text/
[% USE CGI %]
[% CGI.param('param_name') %]
[% CGI.start_form %]
[% CGI.popup_menu( Name => 'color',
Values => [ 'Green', 'Brown' ] ) %]
[% CGI.end_form %]
/tmp/mydata:
# define names for each field
id : email : name : tel
# here's the data
fred : fred@here.com : Fred Smith : 555-1234
bill : bill@here.com : Bill White : 555-5678
example:
[% USE userlist = datafile('/tmp/mydata') %]
[% FOREACH user = userlist %]
[% user.name %] ([% user.id %])
[% END %]
[% USE date %]
[% date.format %] # current time/date
File last modified: [% date.format(template.modtime) %]
[% USE dir = Directory('/tmp') %]
[% FOREACH file = dir.files %]
# all the plain files in the directory
[% END %]
[% FOREACH file = dir.dirs %]
# all the sub-directories
[% END %]
[% USE DBI('dbi:driver:database', 'user', 'pass') %]
[% FOREACH user = DBI.query( 'SELECT * FROM users' ) %]
[% user.id %] [% user.name %]
[% END %]
The DBI and relevant DBD modules are available from CPAN:
http://www.cpan.org/modules/by-module/DBI/
[% USE dumper(indent=0, pad="<br>") %]
[% dumper.dump(myvar, yourvar) %]
[% USE File('/tmp/foo.html') %]
[% File.name %] # foo.html
[% File.dir %] # /tmp
[% File.mtime %] # modification time
package MyOrg::Template::Plugin::MyFilter;
use Template::Plugin::Filter;
use base qw( Template::Plugin::Filter );
sub filter {
my ($self, $text) = @_;
# ...mungify $text...
return $text;
}
# now load it...
[% USE MyFilter %]
# ...and use the returned object as a filter
[% FILTER $MyFilter %]
...
[% END %]
See Template::Plugin::Filter for further details.
[% USE bold = format('<b>%s</b>') %]
[% bold('Hello') %]
[% FILTER null;
USE im = GD.Image(100,100);
# allocate some colors
black = im.colorAllocate(0, 0, 0);
red = im.colorAllocate(255,0, 0);
blue = im.colorAllocate(0, 0, 255);
# Draw a blue oval
im.arc(50,50,95,75,0,360,blue);
# And fill it with red
im.fill(50,50,red);
# Output image in PNG format
im.png | stdout(1);
END;
-%]
See Template::Plugin::GD::Image for further details.
[% FILTER null;
USE gd = GD.Image(200,400);
USE gdc = GD.Constants;
black = gd.colorAllocate(0, 0, 0);
green = gd.colorAllocate(0, 255, 0);
txt = "This is some long text. " | repeat(10);
USE wrapbox = GD.Text.Wrap(gd,
line_space => 4,
color => green,
text => txt,
);
wrapbox.set_font(gdc.gdMediumBoldFont);
wrapbox.set(align => 'center', width => 160);
wrapbox.draw(20, 20);
gd.png | stdout(1);
END;
-%]
See Template::Plugin::GD::Text, Template::Plugin::GD::Text::Align and Template::Plugin::GD::Text::Wrap for further details.
[% FILTER null;
data = [
["1st","2nd","3rd","4th","5th","6th"],
[ 4, 2, 3, 4, 3, 3.5]
];
USE my_graph = GD.Graph.pie(250, 200);
my_graph.set(
title => 'A Pie Chart',
label => 'Label',
axislabelclr => 'black',
pie_height => 36,
transparent => 0,
);
my_graph.plot(data).png | stdout(1);
END;
-%]
See Template::Plugin::GD::Graph::lines, Template::Plugin::GD::Graph::bars, Template::Plugin::GD::Graph::points, Template::Plugin::GD::Graph::linespoints, Template::Plugin::GD::Graph::area, Template::Plugin::GD::Graph::mixed, Template::Plugin::GD::Graph::pie, and GD::Graph, for more details.
[% FILTER null;
data = [
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],
];
USE my_graph = GD.Graph.bars3d();
my_graph.set(
x_label => 'X Label',
y_label => 'Y label',
title => 'A 3d Bar Chart',
y_max_value => 8,
y_tick_number => 8,
y_label_skip => 2,
# shadows
bar_spacing => 8,
shadow_depth => 4,
shadowclr => 'dred',
transparent => 0,
my_graph.plot(data).png | stdout(1);
END;
-%]
See Template::Plugin::GD::Graph::lines3d, Template::Plugin::GD::Graph::bars3d, and Template::Plugin::GD::Graph::pie3d for more details.
[% USE HTML %]
[% HTML.escape("if (a < b && c > d) ..." %]
[% HTML.attributes(border => 1, cellpadding => 2) %]
[% HTML.element(table => { border => 1, cellpadding => 2 }) %]
See Template::Plugin::HTML for further details.
[% USE iterator(list, args) %]
[% FOREACH item = iterator %]
[% '<ul>' IF iterator.first %]
<li>[% item %]
[% '</ul>' IF iterator.last %]
[% END %]
[% USE Pod(podfile) %]
[% FOREACH head1 = Pod.head1;
FOREACH head2 = head1/head2;
...
END;
END
%]
[% USE String 'Hello' %]
[% String.append(' World') %]
[% msg = String.new('Another string') %]
[% msg.replace('string', 'text') %]
The string "[% msg %]" is [% msg.length %] characters long.
[% USE table(list, rows=10, overlap=1) %]
[% FOREACH item = table.col(3) %]
[% item %]
[% END %]
[% USE mycgi = url('/cgi-bin/bar.pl', debug=1) %]
[% mycgi %]
# ==> /cgi/bin/bar.pl?debug=1
[% mycgi(mode='submit') %]
# ==> /cgi/bin/bar.pl?mode=submit&debug=1
[% USE wrap %]
[% wrap(mytext, 40, '* ', ' ') %] # use wrap sub
[% mytext FILTER wrap(40) -%] # or wrap FILTER
The Text::Wrap module is available from CPAN:
http://www.cpan.org/modules/by-module/Text/
[% USE dom = XML.DOM %]
[% doc = dom.parse(filename) %]
[% FOREACH node = doc.getElementsByTagName('CODEBASE') %]
* [% node.getAttribute('href') %]
[% END %]
The plugin requires the XML::DOM module, available from CPAN:
http://www.cpan.org/modules/by-module/XML/
[% USE news = XML.RSS(filename) %]
[% FOREACH item = news.items %]
<a href="[% item.link %]">[% item.title %]</a>
[% END %]
The XML::RSS module is available from CPAN:
http://www.cpan.org/modules/by-module/XML/
[% USE xml = XML.Simple(xml_file_or_text) %]
[% xml.head.title %]
See Template::Plugin::XML::Simple for further details.
[% USE xmlstyle
table = {
attributes = {
border = 0
cellpadding = 4
cellspacing = 1
}
}
%]
[% FILTER xmlstyle %]
<table>
<tr>
<td>Foo</td> <td>Bar</td> <td>Baz</td>
</tr>
</table>
[% END %]
See Template::Plugin::XML::Style for further details.
[% USE xpath = XML.XPath(xmlfile) %]
[% FOREACH page = xpath.findnodes('/html/body/page') %]
[% page.getAttribute('title') %]
[% END %]
The plugin requires the XML::XPath module, available from CPAN:
http://www.cpan.org/modules/by-module/XML/
<http://www.andywardley.com/|http://www.andywardley.com/>
Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
Закладки на сайте Проследить за страницей |
Created 1996-2025 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |