1 #============================================================= -*-Perl-*-
3 # Template::Plugin::CGI
6 # Simple Template Toolkit plugin interfacing to the CGI.pm module.
9 # Andy Wardley <abw@wardley.org>
12 # Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
14 # This module is free software; you can redistribute it and/or
15 # modify it under the same terms as Perl itself.
17 #============================================================================
19 package Template::Plugin::CGI;
23 use base 'Template::Plugin';
34 # monkeypatch CGI::params() method to Do The Right Thing in TT land
40 return $self->{ _TT_PARAMS } ||= do {
41 # must call Vars() in a list context to receive
42 # plain list of key/vals rather than a tied hash
43 my $params = { $self->Vars() };
45 # convert any null separated values into lists
46 @$params{ keys %$params } = map {
47 /\0/ ? [ split /\0/ ] : $_
60 Template::Plugin::CGI - Interface to the CGI module
65 [% CGI.param('parameter') %]
67 [% USE things = CGI %]
68 [% things.param('name') %]
70 # see CGI docs for other methods provided by the CGI object
74 This is a very simple Template Toolkit Plugin interface to the C<CGI> module.
75 A C<CGI> object will be instantiated via the following directive:
79 C<CGI> methods may then be called as follows:
82 [% CGI.param('parameter') %]
84 An alias can be used to provide an alternate name by which the object should
88 [% mycgi.start_form %]
89 [% mycgi.popup_menu({ Name => 'Color'
90 Values => [ 'Green' 'Black' 'Brown' ] }) %]
92 Parenthesised parameters to the C<USE> directive will be passed to the plugin
95 [% USE cgiprm = CGI('uid=abw&name=Andy+Wardley') %]
96 [% cgiprm.param('uid') %]
100 In addition to all the methods supported by the C<CGI> module, this
101 plugin defines the following.
105 This method returns a reference to a hash of all the C<CGI> parameters.
106 Any parameters that have multiple values will be returned as lists.
108 [% USE CGI('user=abw&item=foo&item=bar') %]
109 [% CGI.params.user %] # abw
110 [% CGI.params.item.join(', ') %] # foo, bar
114 Andy Wardley E<lt>abw@wardley.orgE<gt> L<http://wardley.org/>
118 Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
120 This module is free software; you can redistribute it and/or
121 modify it under the same terms as Perl itself.
125 L<Template::Plugin>, L<CGI>
131 # perl-indent-level: 4
132 # indent-tabs-mode: nil
135 # vim: expandtab shiftwidth=4: