| 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 | 2 | our $AUTHORITY = 'cpan:TODDR'; | |||||||||||||||||||
| 21 | # ABSTRACT: Simple Template Toolkit plugin interfacing to the CGI.pm module | ||||||||||||||||||||
| 22 | 2 | $Template::Plugin::CGI::VERSION = '3.101'; | |||||||||||||||||||
| 23 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 2 | ▶ | use base 'Template::Plugin'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 2 | ▶ | use CGI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 2 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 29 | 2 | my $class = shift; | |||||||||||||||||||
| 30 | 2 | my $context = shift; | |||||||||||||||||||
| 31 | 2 | CGI->new(@_); | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | # monkeypatch CGI::params() method to Do The Right Thing in TT land | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 3 | ▶ | sub CGI::params { | ||||||||||||||||||
|
Subroutine
params: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 37 | 3 | my $self = shift; | |||||||||||||||||||
| 38 | 3 | local $" = ', '; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 3 | ▶ | return $self->{ _TT_PARAMS } ||= do { | ||||||||||||||||||
|
Condition66%2/3
$self->{"_TT_PARAMS"} ||= do {
my $params = {$self->Vars};
@$params{keys %$params} = map({/\0/ ? [split(/\0/, $_, 0)] : $_;} values %$params);
$params
}
MC/DC0%0/2
$self->{"_TT_PARAMS"} ||= do {
my $params = {$self->Vars};
@$params{keys %$params} = map({/\0/ ? [split(/\0/, $_, 0)] : $_;} values %$params);
$params
}
$self->{"_TT_PARAMS"}
do {
my $params = {$self->Vars};
@$params{keys %$params} = map({/\0/ ? [split(/\0/, $_, 0)] : $_;} values %$params);
$params
}
Truth table66%2/3
A ||= B
A= $self->{"_TT_PARAMS"}B= do {
my $params = {$self->Vars};
@$params{keys %$params} = map({/\0/ ? [split(/\0/, $_, 0)] : $_;} values %$params);
$params
}
| |||||||||||||||||||||
| 41 | # must call Vars() in a list context to receive | ||||||||||||||||||||
| 42 | # plain list of key/vals rather than a tied hash | ||||||||||||||||||||
| 43 | 1 | my $params = { $self->Vars() }; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | # convert any null separated values into lists | ||||||||||||||||||||
| 46 | @$params{ keys %$params } = map { | ||||||||||||||||||||
| 47 | 1 | ▶ | /\0/ ? [ split /\0/ ] : $_ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | } values %$params; | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 1 | $params; | |||||||||||||||||||
| 51 | }; | ||||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 2 | 1; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =pod | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =encoding UTF-8 | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =head1 NAME | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | Template::Plugin::CGI - Simple Template Toolkit plugin interfacing to the CGI.pm module | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =head1 VERSION | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | version 3.101 | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | =head1 SYNOPSIS | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | [% USE CGI %] | ||||||||||||||||||||
| 71 | [% CGI.param('parameter') %] | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | [% USE things = CGI %] | ||||||||||||||||||||
| 74 | [% things.param('name') %] | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | # see CGI docs for other methods provided by the CGI object | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | =head1 DESCRIPTION | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | This is a very simple Template Toolkit Plugin interface to the C<CGI> module. | ||||||||||||||||||||
| 81 | A C<CGI> object will be instantiated via the following directive: | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | [% USE CGI %] | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | C<CGI> methods may then be called as follows: | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | [% CGI.header %] | ||||||||||||||||||||
| 88 | [% CGI.param('parameter') %] | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | An alias can be used to provide an alternate name by which the object should | ||||||||||||||||||||
| 91 | be identified. | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | [% USE mycgi = CGI %] | ||||||||||||||||||||
| 94 | [% mycgi.start_form %] | ||||||||||||||||||||
| 95 | [% mycgi.popup_menu({ Name => 'Color' | ||||||||||||||||||||
| 96 | Values => [ 'Green' 'Black' 'Brown' ] }) %] | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | Parenthesised parameters to the C<USE> directive will be passed to the plugin | ||||||||||||||||||||
| 99 | constructor: | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | [% USE cgiprm = CGI('uid=abw&name=Andy+Wardley') %] | ||||||||||||||||||||
| 102 | [% cgiprm.param('uid') %] | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =head1 NAME | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | Template::Plugin::CGI - Interface to the CGI module | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =head1 METHODS | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | In addition to all the methods supported by the C<CGI> module, this | ||||||||||||||||||||
| 111 | plugin defines the following. | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | =head2 params() | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | This method returns a reference to a hash of all the C<CGI> parameters. | ||||||||||||||||||||
| 116 | Any parameters that have multiple values will be returned as lists. | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | [% USE CGI('user=abw&item=foo&item=bar') %] | ||||||||||||||||||||
| 119 | [% CGI.params.user %] # abw | ||||||||||||||||||||
| 120 | [% CGI.params.item.join(', ') %] # foo, bar | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | =head1 AUTHOR | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | Andy Wardley E<lt>abw@wardley.orgE<gt> L<http://wardley.org/> | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =head1 COPYRIGHT | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved. | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | This module is free software; you can redistribute it and/or | ||||||||||||||||||||
| 131 | modify it under the same terms as Perl itself. | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | =head1 SEE ALSO | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | L<Template::Plugin>, L<CGI> | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | =head1 AUTHOR | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | Andy Wardley | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | This software is Copyright (c) 2022 by Andy Wardley. | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | This is free software, licensed under: | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | The MIT (X11) License | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | __END__ | ||||||||||||||||||||