Templat...gin::CGI(3)

πŸ’… Templat...gin::CGI(3) β€” the one and only

ok so bestie, this is a page from the User Contributed Perl Documentation and honestly? it's giving "small but mighty." it's the manual for Template::Plugin::CGI, and we're gonna go through it together, no cap 🫢


🌸 NAME 🌸

Template::Plugin::CGI β€” a simple Template Toolkit plugin that interfaces to the CGI.pm module. that's it, that's the whole vibe. ✨


πŸŽ€ VERSION πŸŽ€

version 3.101 β€” periodt, that's the version, don't @ me.


πŸ¦‹ SYNOPSIS πŸ¦‹

ok so here's the whole thing in action:

[% USE CGI %]
[% CGI.param('parameter') %]

[% USE things = CGI %]
[% things.param('name') %]

# see CGI docs for other methods provided by the CGI object

like, you literally just USE it and go. and bestie, that last line is important: see the CGI docs for other methods provided by the CGI object β€” this plugin isn't the whole menu, iykyk πŸ’…


⭐ DESCRIPTION ⭐

okay so real talk: this is a very simple Template Toolkit Plugin interface to the CGI module. a CGI object gets instantiated via this directive right here:

[% USE CGI %]

and then CGI methods may be called like this:

[% CGI.header %]
[% CGI.param('parameter') %]

slay. now β€” you can also use an alias to give the object a different name to be identified by. iconic behaviour:

[% USE mycgi = CGI %]
[% mycgi.start_form %]
[% mycgi.popup_menu({ Name   => 'Color'
                      Values => [ 'Green' 'Black' 'Brown' ] }) %]

and here's the ✨extra✨ part: parenthesised parameters to the USE directive get passed to the plugin constructor:

[% USE cgiprm = CGI('uid=abw&name=Andy+Wardley') %]
[% cgiprm.param('uid') %]

look at that. parameters going straight into the constructor. we love to see it 🧚


🌈 NAME (again, yes really) 🌈

so the page does the NAME thing a second time, and honestly? main character energy. it says:

Template::Plugin::CGI β€” Interface to the CGI module

short, sweet, to the point. πŸ’œ


πŸ”₯ METHODS πŸ”₯

so in addition to all the methods supported by the CGI module, this plugin defines the following. yes, in addition to. you're not losing anything, you're gaining 😌

πŸ“ params() πŸ“

this one returns a reference to a hash of all the CGI parameters. and listen β€” any parameters that have multiple values will be returned as lists. so if a param shows up more than once, you get a whole list, not just one sad value. look:

[% USE CGI('user=abw&item=foo&item=bar') %]
[% CGI.params.user %]            # abw
[% CGI.params.item.join(', ') %] # foo, bar

see how user is just abw but item has two entries? yeah. join(', ') ate that. πŸ”₯


🫢 AUTHOR 🫢

Andy Wardley <abw@wardley.org> <http://wardley.org/>

(go follow the link bestie, it's literally right there πŸ’–)


Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.

and then the licensing bit, which is important so pay attention:

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

that's the whole deal. free software, same terms as Perl itself, no funny business. 🌸


πŸ’€ SEE ALSO πŸ’€

  • Template::Plugin
  • CGI

go read those too, they're literally the siblings of this page. iykyk πŸ¦‹


⭐ AUTHOR (yes, a second one) ⭐

Andy Wardley β€” again. the man is consistent. πŸ‘‘


This software is Copyright (c) 2022 by Andy Wardley.

and it's free software, licensed under:

The MIT (X11) License

that's the license, no cap. read it if you're gonna redistribute, bestie. πŸ’…


okay and the last thing, the little footer crumbs: this page was generated for perl v5.40.0 and dated 2024-07-19, brought to you by the lovely humans doing the Perl docs thing. go forth and USE CGI responsibly, mwah πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from