VERSION

SYNOPSIS

DESCRIPTION

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.

Methods

new

my $handler = Some::Handler::Subclass->new( $cgi, $param );

Returns a new handler object. Returns nothing if the parameter is required but not present.

has_param

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.

has_virtual_param

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:

Note that the this method will automatically report the parameter as "missing" to the Class::CGI object if it's a required parameter.

handle

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.

cgi

my $cgi = $handler->cgi;

Returns the Class::CGI object used to call the handler.

param

my $param = $cgi->param;

Returns the parameter name the user has requested.

_missing

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.

TODO

This module should be considered alpha code. It probably has bugs. Comments and suggestions welcome.