Class::CGI::Handler - Base class for Class::CGI handlers
Version 0.20
use base 'Class::CGI::Handler'; sub handle { my $self = shift; my $cgi = $self->cgi; my $param = $self->param; # validate stuff and return anything you want }
Handlers for Class::CGI should inherit from this class. This class provides a constructor which builds the handler object and checks to see if the param value from the CGI data is required. If so, it will automatically set a "missing" error if the parameter is not present. See the has_param method for more details.
Class::CGI
my $handler = Some::Handler::Subclass->new( $cgi, $param );
Returns a new handler object. Returns nothing if the parameter is required but not present.
if ( $handler->has_param ) { ... }
Returns a boolean value indicating whether or not the current parameter was found in the form. If a parameter is "real", that is to say, the requested parameter name and the actual parameter name are identical, then this method should be all you need. For example:
In the HTML:
<input type="text" name="age"/>
In the code:
my $age = $cgi->param('age');
If the parameter is "virtual" (the requested parameter name does not match the name in the HTML), then this method should be overridden in your subclass.
Note that the this method will automatically report the parameter as "missing" to the Class::CGI object if it's a required parameter.
if ( $cgi->has_virtual_param( $param, @list_of_parameters ) ) { }
Very similar to the has_param method. However, instead of checking to see if the current parameter exists, you pass in the name of the virtual parameter and a list of the component parameters which comprise the virtual parameter. For example:
has_param
if ( $handler->has_virtual_param( 'date', qw/day month year/ ) ) { .... }
return $handler->handle;
This method must be overridden in a subclass. It is the primary method used to actually validate and optionally untaint form data and return the appropriate data. See WRITING HANDLERS in the Class::CGI documentation.
WRITING HANDLERS
my $cgi = $handler->cgi;
Returns the Class::CGI object used to call the handler.
my $param = $cgi->param;
Returns the parameter name the user has requested.
if ( my %missing = $handler->_missing(@params) ) { ... }
This is a protected method which should only be called by subclasses.
Given a list of parameter names (actual, not virtual), this method will return a hash of all parameters whose value is undefined or the empty string. The keys are the parameter names and the values are the value received from the Class::CGI object.
This module should be considered alpha code. It probably has bugs. Comments and suggestions welcome.
The only current "TODO" is to allow overridding error messages.
Curtis "Ovid" Poe, <ovid@cpan.org>
<ovid@cpan.org>
There is a mailing list at http://groups.yahoo.com/group/class_cgi/. Currently it is low volume. That might change in the future.
Please report any bugs or feature requests to bug-class-cgi@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-CGI. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-class-cgi@rt.cpan.org
If you are unsure if a particular behavior is a bug, feel free to send mail to the mailing list.
Copyright 2006 Curtis "Ovid" Poe, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Class::CGI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::CGI
CPAN shell
perl -MCPAN -e shell install Class::CGI
For more information on module installation, please visit the detailed CPAN module installation guide.