home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Plugins.pod < prev    next >
Encoding:
Text File  |  2004-01-30  |  15.8 KB  |  553 lines

  1. #============================================================= -*-perl-*-
  2. #
  3. # Template::Manual::Plugins
  4. #
  5. # DESCRIPTION
  6. #   This section lists the standard plugins which can be used to extend
  7. #   the runtime functionality of the Template Toolkit. The plugins are
  8. #   distributed with the Template Toolkit but may required additional
  9. #   modules from CPAN.
  10. #
  11. # AUTHOR
  12. #   Andy Wardley  <abw@andywardley.com>
  13. #
  14. # COPYRIGHT
  15. #   Copyright (C) 1996-2001 Andy Wardley.  All Rights Reserved.
  16. #   Copyright (C) 1998-2001 Canon Research Centre Europe Ltd.
  17. #
  18. #   This module is free software; you can redistribute it and/or
  19. #   modify it under the same terms as Perl itself.
  20. #
  21. # REVISION
  22. #   
  23. #
  24. #========================================================================
  25.  
  26.  
  27. #------------------------------------------------------------------------
  28. # IMPORTANT NOTE
  29. #   This documentation is generated automatically from source
  30. #   templates.  Any changes you make here may be lost.
  31. #   The 'docsrc' documentation source bundle is available for download
  32. #   from http://www.template-toolkit.org/docs.html and contains all
  33. #   the source templates, XML files, scripts, etc., from which the
  34. #   documentation for the Template Toolkit is built.
  35. #------------------------------------------------------------------------
  36.  
  37. =head1 NAME
  38.  
  39. Template::Manual::Plugins - Standard plugins
  40.  
  41. =head1 DESCRIPTION
  42.  
  43. This section lists the standard plugins which can be used to extend the
  44. runtime functionality of the Template Toolkit. The plugins are
  45. distributed with the Template Toolkit but may required additional
  46. modules from CPAN.
  47.  
  48.  
  49.  
  50. =head1 TEMPLATE TOOLKIT PLUGINS
  51.  
  52. The following plugin modules are distributed with the Template
  53. Toolkit.  Some of the plugins interface to external modules (detailed
  54. below) which should be downloaded from any CPAN site and installed
  55. before using the plugin.
  56.  
  57. =head2 Autoformat
  58.  
  59. The Autoformat plugin is an interface to Damian Conway's Text::Autoformat 
  60. Perl module which provides advanced text wrapping and formatting.  See
  61. L<Template::Plugin::Autoformat> and L<Text::Autoformat> for further 
  62. details.
  63.  
  64.     [% USE autoformat(left=10, right=20) %]
  65.     [% autoformat(mytext) %]        # call autoformat sub
  66.     [% mytext FILTER autoformat %]  # or use autoformat filter
  67.  
  68. The Text::Autoformat module is available from CPAN:
  69.  
  70.     http://www.cpan.org/modules/by-module/Text/
  71.  
  72. =head2 CGI
  73.  
  74. The CGI plugin is a wrapper around Lincoln Stein's 
  75. E<lt>lstein@genome.wi.mit.eduE<gt> CGI.pm module.  The plugin is 
  76. distributed with the Template Toolkit (see L<Template::Plugin::CGI>)
  77. and the CGI module itself is distributed with recent versions Perl,
  78. or is available from CPAN.
  79.  
  80.     [% USE CGI %]
  81.     [% CGI.param('param_name') %]
  82.     [% CGI.start_form %]
  83.     [% CGI.popup_menu( Name   => 'color', 
  84.                        Values => [ 'Green', 'Brown' ] ) %]
  85.     [% CGI.end_form %]
  86.  
  87. =head2 Datafile
  88.  
  89. Provides an interface to data stored in a plain text file in a simple
  90. delimited format.  The first line in the file specifies field names
  91. which should be delimiter by any non-word character sequence.
  92. Subsequent lines define data using the same delimiter as int he first
  93. line.  Blank lines and comments (lines starting '#') are ignored.  See
  94. L<Template::Plugin::Datafile> for further details.
  95.  
  96. /tmp/mydata:
  97.  
  98.     # define names for each field
  99.     id : email : name : tel
  100.     # here's the data
  101.     fred : fred@here.com : Fred Smith : 555-1234
  102.     bill : bill@here.com : Bill White : 555-5678
  103.  
  104. example:
  105.  
  106.     [% USE userlist = datafile('/tmp/mydata') %]
  107.  
  108.     [% FOREACH user = userlist %]
  109.        [% user.name %] ([% user.id %])
  110.     [% END %]
  111.  
  112. =head2 Date
  113.  
  114. The Date plugin provides an easy way to generate formatted time and date
  115. strings by delegating to the POSIX strftime() routine.   See
  116. L<Template::Plugin::Date> and L<POSIX> for further details.
  117.  
  118.     [% USE date %]
  119.     [% date.format %]        # current time/date
  120.  
  121.     File last modified: [% date.format(template.modtime) %]
  122.  
  123. =head2 Directory
  124.  
  125. The Directory plugin provides a simple interface to a directory and
  126. the files within it.  See L<Template::Plugin::Directory> for further
  127. details.
  128.  
  129.     [% USE dir = Directory('/tmp') %]
  130.     [% FOREACH file = dir.files %]
  131.         # all the plain files in the directory
  132.     [% END %]
  133.     [% FOREACH file = dir.dirs %]
  134.         # all the sub-directories
  135.     [% END %]
  136.  
  137. =head2 DBI
  138.  
  139. The DBI plugin, developed by Simon Matthews
  140. E<lt>sam@knowledgepool.comE<gt>, brings the full power of Tim Bunce's
  141. E<lt>Tim.Bunce@ig.co.ukE<gt> database interface module (DBI) to your
  142. templates.  See L<Template::Plugin::DBI> and L<DBI> for further details.
  143.  
  144.     [% USE DBI('dbi:driver:database', 'user', 'pass') %]
  145.  
  146.     [% FOREACH user = DBI.query( 'SELECT * FROM users' ) %]
  147.        [% user.id %] [% user.name %]
  148.     [% END %]
  149.  
  150. The DBI and relevant DBD modules are available from CPAN:
  151.  
  152.   http://www.cpan.org/modules/by-module/DBI/
  153.  
  154. =head2 Dumper
  155.  
  156. The Dumper plugin provides an interface to the Data::Dumper module.  See
  157. L<Template::Plugin::Dumper> and L<Data::Dumper> for futher details.
  158.  
  159.     [% USE dumper(indent=0, pad="<br>") %]
  160.     [% dumper.dump(myvar, yourvar) %]
  161.  
  162. =head2 File
  163.  
  164. The File plugin provides a general abstraction for files and can be
  165. used to fetch information about specific files within a filesystem.
  166. See L<Template::Plugin::File> for further details.
  167.  
  168.     [% USE File('/tmp/foo.html') %]
  169.     [% File.name %]     # foo.html
  170.     [% File.dir %]      # /tmp
  171.     [% File.mtime %]    # modification time
  172.  
  173. =head2 Filter
  174.  
  175. This module implements a base class plugin which can be subclassed
  176. to easily create your own modules that define and install new filters.
  177.  
  178.     package MyOrg::Template::Plugin::MyFilter;
  179.  
  180.     use Template::Plugin::Filter;
  181.     use base qw( Template::Plugin::Filter );
  182.  
  183.     sub filter {
  184.     my ($self, $text) = @_;
  185.  
  186.     # ...mungify $text...
  187.  
  188.     return $text;
  189.     }
  190.  
  191.     # now load it...
  192.     [% USE MyFilter %]
  193.  
  194.     # ...and use the returned object as a filter
  195.     [% FILTER $MyFilter %]
  196.       ...
  197.     [% END %]
  198.  
  199. See L<Template::Plugin::Filter> for further details.
  200.  
  201. =head2 Format
  202.  
  203. The Format plugin provides a simple way to format text according to a
  204. printf()-like format.   See L<Template::Plugin::Format> for further 
  205. details.
  206.  
  207.     [% USE bold = format('<b>%s</b>') %]
  208.     [% bold('Hello') %]
  209.  
  210. =head2 GD::Image, GD::Polygon, GD::Constants
  211.  
  212. These plugins provide access to the GD graphics library via Lincoln
  213. D. Stein's GD.pm interface.  These plugins allow PNG, JPEG and other
  214. graphical formats to be generated.
  215.  
  216.     [% FILTER null;
  217.         USE im = GD.Image(100,100);
  218.         # allocate some colors
  219.         black = im.colorAllocate(0,   0, 0);
  220.         red   = im.colorAllocate(255,0,  0);
  221.         blue  = im.colorAllocate(0,  0,  255);
  222.         # Draw a blue oval
  223.         im.arc(50,50,95,75,0,360,blue);
  224.         # And fill it with red
  225.         im.fill(50,50,red);
  226.         # Output image in PNG format
  227.         im.png | stdout(1);
  228.        END;
  229.     -%]
  230.  
  231. See L<Template::Plugin::GD::Image> for further details.
  232.  
  233. =head2 GD::Text, GD::Text::Align, GD::Text::Wrap
  234.  
  235. These plugins provide access to Martien Verbruggen's GD::Text,
  236. GD::Text::Align and GD::Text::Wrap modules. These plugins allow the
  237. layout, alignment and wrapping of text when drawing text in GD images.
  238.  
  239.     [% FILTER null;
  240.         USE gd  = GD.Image(200,400);
  241.         USE gdc = GD.Constants;
  242.         black = gd.colorAllocate(0,   0, 0);
  243.         green = gd.colorAllocate(0, 255, 0);
  244.         txt = "This is some long text. " | repeat(10);
  245.         USE wrapbox = GD.Text.Wrap(gd,
  246.          line_space  => 4,
  247.          color       => green,
  248.          text        => txt,
  249.         );
  250.         wrapbox.set_font(gdc.gdMediumBoldFont);
  251.         wrapbox.set(align => 'center', width => 160);
  252.         wrapbox.draw(20, 20);
  253.         gd.png | stdout(1);
  254.       END;
  255.     -%]
  256.  
  257. See L<Template::Plugin::GD::Text>, L<Template::Plugin::GD::Text::Align>
  258. and L<Template::Plugin::GD::Text::Wrap> for further details.
  259.  
  260. =head2 GD::Graph::lines, GD::Graph::bars, GD::Graph::points, GD::Graph::linespoin
  261. ts, GD::Graph::area, GD::Graph::mixed, GD::Graph::pie
  262.  
  263. These plugins provide access to Martien Verbruggen's GD::Graph module
  264. that allows graphs, plots and charts to be created. These plugins allow
  265. graphs, plots and charts to be generated in PNG, JPEG and other
  266. graphical formats.
  267.  
  268.     [% FILTER null;
  269.         data = [
  270.             ["1st","2nd","3rd","4th","5th","6th"],
  271.             [    4,    2,    3,    4,    3,  3.5]
  272.         ];
  273.         USE my_graph = GD.Graph.pie(250, 200);
  274.         my_graph.set(
  275.                 title => 'A Pie Chart',
  276.                 label => 'Label',
  277.                 axislabelclr => 'black',
  278.                 pie_height => 36,
  279.                 transparent => 0,
  280.         );
  281.         my_graph.plot(data).png | stdout(1);
  282.       END;
  283.     -%]
  284.  
  285. See
  286. L<Template::Plugin::GD::Graph::lines>,
  287. L<Template::Plugin::GD::Graph::bars>,
  288. L<Template::Plugin::GD::Graph::points>,
  289. L<Template::Plugin::GD::Graph::linespoints>,
  290. L<Template::Plugin::GD::Graph::area>,
  291. L<Template::Plugin::GD::Graph::mixed>,
  292. L<Template::Plugin::GD::Graph::pie>, and
  293. L<GD::Graph>,
  294. for more details.
  295.  
  296. =head2 GD::Graph::bars3d, GD::Graph::lines3d, GD::Graph::pie3d
  297.  
  298. These plugins provide access to Jeremy Wadsack's GD::Graph3d
  299. module.  This allows 3D bar charts and 3D lines plots to
  300. be generated.
  301.  
  302.     [% FILTER null;
  303.         data = [
  304.             ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
  305.             [    1,    2,    5,    6,    3,  1.5,    1,     3,     4],
  306.         ];
  307.         USE my_graph = GD.Graph.bars3d();
  308.         my_graph.set(
  309.             x_label         => 'X Label',
  310.             y_label         => 'Y label',
  311.             title           => 'A 3d Bar Chart',
  312.             y_max_value     => 8,
  313.             y_tick_number   => 8,
  314.             y_label_skip    => 2,
  315.             # shadows
  316.             bar_spacing     => 8,
  317.             shadow_depth    => 4,
  318.             shadowclr       => 'dred',
  319.             transparent     => 0,
  320.         my_graph.plot(data).png | stdout(1);
  321.       END;
  322.     -%]
  323.  
  324. See
  325. L<Template::Plugin::GD::Graph::lines3d>,
  326. L<Template::Plugin::GD::Graph::bars3d>, and
  327. L<Template::Plugin::GD::Graph::pie3d>
  328. for more details.
  329.  
  330. =head2 HTML
  331.  
  332. The HTML plugin is very new and very basic, implementing a few useful
  333. methods for generating HTML.  It is likely to be extended in the future
  334. or integrated with a larger project to generate HTML elements in a generic
  335. way (as discussed recently on the mod_perl mailing list).
  336.  
  337.     [% USE HTML %]
  338.     [% HTML.escape("if (a < b && c > d) ..." %]
  339.     [% HTML.attributes(border => 1, cellpadding => 2) %]
  340.     [% HTML.element(table => { border => 1, cellpadding => 2 }) %]
  341.  
  342. See L<Template::Plugin::HTML> for further details.
  343.  
  344. =head2 Iterator
  345.  
  346. The Iterator plugin provides a way to create a Template::Iterator
  347. object to iterate over a data set.  An iterator is created
  348. automatically by the FOREACH directive and is aliased to the 'loop'
  349. variable.  This plugin allows an iterator to be explicitly created
  350. with a given name, or the default plugin name, 'iterator'.  See
  351. L<Template::Plugin::Iterator> for further details.
  352.  
  353.     [% USE iterator(list, args) %]
  354.  
  355.     [% FOREACH item = iterator %]
  356.        [% '<ul>' IF iterator.first %]
  357.        <li>[% item %]
  358.        [% '</ul>' IF iterator.last %]
  359.     [% END %]
  360.  
  361. =head2 Pod
  362.  
  363. This plugin provides an interface to the L<Pod::POM|Pod::POM> module
  364. which parses POD documents into an internal object model which can
  365. then be traversed and presented through the Template Toolkit.
  366.  
  367.     [% USE Pod(podfile) %]
  368.  
  369.     [% FOREACH head1 = Pod.head1;
  370.      FOREACH head2 = head1/head2;
  371.        ...
  372.          END;
  373.        END
  374.     %]
  375.  
  376. =head2 String
  377.  
  378. The String plugin implements an object-oriented interface for 
  379. manipulating strings.  See L<Template::Plugin::String> for further 
  380. details.
  381.  
  382.     [% USE String 'Hello' %]
  383.     [% String.append(' World') %]
  384.  
  385.     [% msg = String.new('Another string') %]
  386.     [% msg.replace('string', 'text') %]
  387.  
  388.     The string "[% msg %]" is [% msg.length %] characters long.
  389.  
  390. =head2 Table
  391.  
  392. The Table plugin allows you to format a list of data items into a 
  393. virtual table by specifying a fixed number of rows or columns, with 
  394. an optional overlap.  See L<Template::Plugin::Table> for further 
  395. details.
  396.  
  397.     [% USE table(list, rows=10, overlap=1) %]
  398.  
  399.     [% FOREACH item = table.col(3) %]
  400.        [% item %]
  401.     [% END %]
  402.  
  403. =head2 URL
  404.  
  405. The URL plugin provides a simple way of contructing URLs from a base
  406. part and a variable set of parameters.  See L<Template::Plugin::URL>
  407. for further details.
  408.  
  409.     [% USE mycgi = url('/cgi-bin/bar.pl', debug=1) %]
  410.  
  411.     [% mycgi %]
  412.        # ==> /cgi/bin/bar.pl?debug=1
  413.  
  414.     [% mycgi(mode='submit') %]
  415.        # ==> /cgi/bin/bar.pl?mode=submit&debug=1
  416.  
  417. =head2 Wrap
  418.  
  419. The Wrap plugin uses the Text::Wrap module by David Muir Sharnoff 
  420. E<lt>muir@idiom.comE<gt> (with help from Tim Pierce and many many others)
  421. to provide simple paragraph formatting.  See L<Template::Plugin::Wrap>
  422. and L<Text::Wrap> for further details.
  423.  
  424.     [% USE wrap %]
  425.     [% wrap(mytext, 40, '* ', '  ') %]    # use wrap sub
  426.     [% mytext FILTER wrap(40) -%]    # or wrap FILTER
  427.  
  428. The Text::Wrap module is available from CPAN:
  429.  
  430.     http://www.cpan.org/modules/by-module/Text/
  431.  
  432. =head2 XML::DOM
  433.  
  434. The XML::DOM plugin gives access to the XML Document Object Module via
  435. Clark Cooper E<lt>cooper@sch.ge.comE<gt> and Enno Derksen's 
  436. E<lt>enno@att.comE<gt> XML::DOM module.  See L<Template::Plugin::XML::DOM> 
  437. and L<XML::DOM> for further details.
  438.  
  439.     [% USE dom = XML.DOM %]
  440.     [% doc = dom.parse(filename) %]
  441.  
  442.     [% FOREACH node = doc.getElementsByTagName('CODEBASE') %]
  443.        * [% node.getAttribute('href') %]
  444.     [% END %]
  445.  
  446. The plugin requires the XML::DOM module, available from CPAN:
  447.  
  448.     http://www.cpan.org/modules/by-module/XML/
  449.  
  450. =head2 XML::RSS
  451.  
  452. The XML::RSS plugin is a simple interface to Jonathan Eisenzopf's
  453. E<lt>eisen@pobox.comE<gt> XML::RSS module.  A RSS (Rich Site Summary)
  454. file is typically used to store short news 'headlines' describing
  455. different links within a site.  This plugin allows you to parse RSS
  456. files and format the contents accordingly using templates.  
  457. See L<Template::Plugin::XML::RSS> and L<XML::RSS> for further details.
  458.  
  459.     [% USE news = XML.RSS(filename) %]
  460.    
  461.     [% FOREACH item = news.items %]
  462.        <a href="[% item.link %]">[% item.title %]</a>
  463.     [% END %]
  464.  
  465. The XML::RSS module is available from CPAN:
  466.  
  467.     http://www.cpan.org/modules/by-module/XML/
  468.  
  469. =head2 XML::Simple
  470.  
  471. This plugin implements an interface to the L<XML::Simple|XML::Simple>
  472. module.
  473.  
  474.     [% USE xml = XML.Simple(xml_file_or_text) %]
  475.  
  476.     [% xml.head.title %]
  477.  
  478. See L<Template::Plugin::XML::Simple> for further details.
  479.  
  480. =head2 XML::Style
  481.  
  482. This plugin defines a filter for performing simple stylesheet based 
  483. transformations of XML text.  
  484.  
  485.     [% USE xmlstyle 
  486.            table = { 
  487.                attributes = { 
  488.                    border      = 0
  489.                    cellpadding = 4
  490.                    cellspacing = 1
  491.                }
  492.            }
  493.     %]
  494.  
  495.     [% FILTER xmlstyle %]
  496.     <table>
  497.     <tr>
  498.       <td>Foo</td> <td>Bar</td> <td>Baz</td>
  499.     </tr>
  500.     </table>
  501.     [% END %]
  502.  
  503. See L<Template::Plugin::XML::Style> for further details.
  504.  
  505. =head2 XML::XPath
  506.  
  507. The XML::XPath plugin provides an interface to Matt Sergeant's
  508. E<lt>matt@sergeant.orgE<gt> XML::XPath module.  See 
  509. L<Template::Plugin::XML::XPath> and L<XML::XPath> for further details.
  510.  
  511.     [% USE xpath = XML.XPath(xmlfile) %]
  512.     [% FOREACH page = xpath.findnodes('/html/body/page') %]
  513.        [% page.getAttribute('title') %]
  514.     [% END %]
  515.  
  516. The plugin requires the XML::XPath module, available from CPAN:
  517.  
  518.     http://www.cpan.org/modules/by-module/XML/
  519.  
  520. =head1 AUTHOR
  521.  
  522. Andy Wardley E<lt>abw@andywardley.comE<gt>
  523.  
  524. L<http://www.andywardley.com/|http://www.andywardley.com/>
  525.  
  526.  
  527.  
  528.  
  529. =head1 VERSION
  530.  
  531. Template Toolkit version 2.13, released on 30 January 2004.
  532.  
  533. =head1 COPYRIGHT
  534.  
  535.   Copyright (C) 1996-2004 Andy Wardley.  All Rights Reserved.
  536.   Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
  537.  
  538. This module is free software; you can redistribute it and/or
  539. modify it under the same terms as Perl itself.
  540.  
  541.  
  542.  
  543. =cut
  544.  
  545. # Local Variables:
  546. # mode: perl
  547. # perl-indent-level: 4
  548. # indent-tabs-mode: nil
  549. # End:
  550. #
  551. # vim: expandtab shiftwidth=4:
  552.