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 / CGI.pm < prev    next >
Encoding:
Perl POD Document  |  2004-01-30  |  4.0 KB  |  169 lines

  1. #============================================================= -*-Perl-*-
  2. #
  3. # Template::Plugin::CGI
  4. #
  5. # DESCRIPTION
  6. #
  7. #   Simple Template Toolkit plugin interfacing to the CGI.pm module.
  8. #
  9. # AUTHOR
  10. #   Andy Wardley   <abw@kfs.org>
  11. #
  12. # COPYRIGHT
  13. #   Copyright (C) 1996-2000 Andy Wardley.  All Rights Reserved.
  14. #   Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
  15. #
  16. #   This module is free software; you can redistribute it and/or
  17. #   modify it under the same terms as Perl itself.
  18. #
  19. #----------------------------------------------------------------------------
  20. #
  21. # $Id: CGI.pm,v 2.64 2004/01/13 16:20:38 abw Exp $
  22. #
  23. #============================================================================
  24.  
  25. package Template::Plugin::CGI;
  26.  
  27. require 5.004;
  28.  
  29. use strict;
  30. use vars qw( $VERSION );
  31. use base qw( Template::Plugin );
  32. use Template::Plugin;
  33. use CGI;
  34.  
  35. $VERSION = sprintf("%d.%02d", q$Revision: 2.64 $ =~ /(\d+)\.(\d+)/);
  36.  
  37. sub new {
  38.     my $class   = shift;
  39.     my $context = shift;
  40.     CGI->new(@_);
  41. }
  42.  
  43. package CGI;
  44.  
  45. sub params {
  46.     my $self = shift;
  47.     local $" = ', ';
  48.  
  49.     return $self->{ _TT_PARAMS } ||= do {
  50.         # must call Vars() in a list context to receive
  51.         # plain list of key/vals rather than a tied hash
  52.         my $params = { $self->Vars() };
  53.  
  54.         # convert any null separated values into lists
  55.         @$params{ keys %$params } = map { 
  56.             /\0/ ? [ split /\0/ ] : $_ 
  57.         } values %$params;
  58.  
  59.         $params;
  60.     };
  61. }
  62.  
  63. 1;
  64.  
  65. __END__
  66.  
  67.  
  68. #------------------------------------------------------------------------
  69. # IMPORTANT NOTE
  70. #   This documentation is generated automatically from source
  71. #   templates.  Any changes you make here may be lost.
  72. #   The 'docsrc' documentation source bundle is available for download
  73. #   from http://www.template-toolkit.org/docs.html and contains all
  74. #   the source templates, XML files, scripts, etc., from which the
  75. #   documentation for the Template Toolkit is built.
  76. #------------------------------------------------------------------------
  77.  
  78. =head1 NAME
  79.  
  80. Template::Plugin::CGI - Interface to the CGI module
  81.  
  82. =head1 SYNOPSIS
  83.  
  84.     [% USE CGI %]
  85.     [% CGI.param('parameter') %]
  86.  
  87.     [% USE things = CGI %]
  88.     [% things.param('name') %]
  89.     
  90.     # see CGI docs for other methods provided by the CGI object
  91.  
  92. =head1 DESCRIPTION
  93.  
  94. This is a very simple Template Toolkit Plugin interface to the CGI module.
  95. A CGI object will be instantiated via the following directive:
  96.  
  97.     [% USE CGI %]
  98.  
  99. CGI methods may then be called as follows:
  100.  
  101.     [% CGI.header %]
  102.     [% CGI.param('parameter') %]
  103.  
  104. An alias can be used to provide an alternate name by which the object should
  105. be identified.
  106.  
  107.     [% USE mycgi = CGI %]
  108.     [% mycgi.start_form %]
  109.     [% mycgi.popup_menu({ Name   => 'Color'
  110.               Values => [ 'Green' 'Black' 'Brown' ] }) %]
  111.  
  112. Parenthesised parameters to the USE directive will be passed to the plugin 
  113. constructor:
  114.     
  115.     [% USE cgiprm = CGI('uid=abw&name=Andy+Wardley') %]
  116.     [% cgiprm.param('uid') %]
  117.  
  118. =head1 METHODS
  119.  
  120. In addition to all the methods supported by the CGI module, this
  121. plugin defines the following.
  122.  
  123. =head2 params()
  124.  
  125. This method returns a reference to a hash of all the CGI parameters.
  126. Any parameters that have multiple values will be returned as lists.
  127.  
  128.     [% USE CGI('user=abw&item=foo&item=bar') %]
  129.  
  130.     [% CGI.params.user %]            # abw
  131.     [% CGI.params.item.join(', ') %] # foo, bar
  132.  
  133. =head1 AUTHOR
  134.  
  135. Andy Wardley E<lt>abw@andywardley.comE<gt>
  136.  
  137. L<http://www.andywardley.com/|http://www.andywardley.com/>
  138.  
  139.  
  140.  
  141.  
  142. =head1 VERSION
  143.  
  144. 2.64, distributed as part of the
  145. Template Toolkit version 2.13, released on 30 January 2004.
  146.  
  147. =head1 COPYRIGHT
  148.  
  149.   Copyright (C) 1996-2004 Andy Wardley.  All Rights Reserved.
  150.   Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
  151.  
  152. This module is free software; you can redistribute it and/or
  153. modify it under the same terms as Perl itself.
  154.  
  155. =head1 SEE ALSO
  156.  
  157. L<Template::Plugin|Template::Plugin>, L<CGI|CGI>
  158.  
  159. =cut
  160.  
  161. # Local Variables:
  162. # mode: perl
  163. # perl-indent-level: 4
  164. # indent-tabs-mode: nil
  165. # End:
  166. #
  167. # vim: expandtab shiftwidth=4:
  168.