Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / i486-linux-gnu-thread-multi / Template / Plugin / CGI.pm
1 #============================================================= -*-Perl-*-
2 #
3 # Template::Plugin::CGI
4 #
5 # DESCRIPTION
6 #   Simple Template Toolkit plugin interfacing to the CGI.pm module.
7 #
8 # AUTHOR
9 #   Andy Wardley   <abw@wardley.org>
10 #
11 # COPYRIGHT
12 #   Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.
13 #
14 #   This module is free software; you can redistribute it and/or
15 #   modify it under the same terms as Perl itself.
16 #
17 #============================================================================
18
19 package Template::Plugin::CGI;
20
21 use strict;
22 use warnings;
23 use base 'Template::Plugin';
24 use CGI;
25
26 our $VERSION = 2.70;
27
28 sub new {
29     my $class   = shift;
30     my $context = shift;
31     CGI->new(@_);
32 }
33
34 # monkeypatch CGI::params() method to Do The Right Thing in TT land
35
36 sub CGI::params {
37     my $self = shift;
38     local $" = ', ';
39
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() };
44
45         # convert any null separated values into lists
46         @$params{ keys %$params } = map { 
47             /\0/ ? [ split /\0/ ] : $_ 
48         } values %$params;
49
50         $params;
51     };
52 }
53
54 1;
55
56 __END__
57
58 =head1 NAME
59
60 Template::Plugin::CGI - Interface to the CGI module
61
62 =head1 SYNOPSIS
63
64     [% USE CGI %]
65     [% CGI.param('parameter') %]
66     
67     [% USE things = CGI %]
68     [% things.param('name') %]
69     
70     # see CGI docs for other methods provided by the CGI object
71
72 =head1 DESCRIPTION
73
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:
76
77     [% USE CGI %]
78
79 C<CGI> methods may then be called as follows:
80
81     [% CGI.header %]
82     [% CGI.param('parameter') %]
83
84 An alias can be used to provide an alternate name by which the object should
85 be identified.
86
87     [% USE mycgi = CGI %]
88     [% mycgi.start_form %]
89     [% mycgi.popup_menu({ Name   => 'Color'
90                           Values => [ 'Green' 'Black' 'Brown' ] }) %]
91
92 Parenthesised parameters to the C<USE> directive will be passed to the plugin 
93 constructor:
94
95     [% USE cgiprm = CGI('uid=abw&name=Andy+Wardley') %]
96     [% cgiprm.param('uid') %]
97
98 =head1 METHODS
99
100 In addition to all the methods supported by the C<CGI> module, this
101 plugin defines the following.
102
103 =head2 params()
104
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.
107
108     [% USE CGI('user=abw&item=foo&item=bar') %]
109     [% CGI.params.user %]            # abw
110     [% CGI.params.item.join(', ') %] # foo, bar
111
112 =head1 AUTHOR
113
114 Andy Wardley E<lt>abw@wardley.orgE<gt> L<http://wardley.org/>
115
116 =head1 COPYRIGHT
117
118 Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.
119
120 This module is free software; you can redistribute it and/or
121 modify it under the same terms as Perl itself.
122
123 =head1 SEE ALSO
124
125 L<Template::Plugin>, L<CGI>
126
127 =cut
128
129 # Local Variables:
130 # mode: perl
131 # perl-indent-level: 4
132 # indent-tabs-mode: nil
133 # End:
134 #
135 # vim: expandtab shiftwidth=4: