Why not adopt me?
NAME
CGI::Apache2::Wrapper - provide param() and header() via mod_perl
SYNOPSIS
sub handler {
my $r = shift;
my $cgi = CGI::Apache2::Wrapper->new($r);
my $foo = $cgi->param("foo");
my $header = {'Content-Type' => 'text/plain; charset=utf-8',
'X-err_header_out' => 'err_headers_out',
};
$cgi->header($header);
$r->print("You passed in $foo\n");
return Apache2::Const::OK;
}
DESCRIPTION
Certain modules, such as CGI::Ajax and JavaScript::Autocomplete::Backend, require a minimal CGI.pm-compatible module to provide, in particular, the param() and header() methods to, respectively, fetch parameters and to set the headers. The standard module to do this is of course CGI.pm; however, especially in a mod_perl environment, there may be concerns with the resultant memory footprint. This module provides param() and header() methods (as well as remote_addr() and url() via mod_perl2 and librapreq2, and as such, it may be a viable alternative in a mod_perl scenario. However, due to the nature of the required APR modules needed here, this module may also be used in a CGI environment.
methods
Methods available are as follows.
my $cgi = CGI::Apache2::Wrapper->new($r);
This method creates a CGI::Apache2::Wrapper object. In a CGI environment no arguments are passed into new(), but in a mod_perl environment, the Apache2::RequestRec object $r should be passed in as an argument.
my $value = $cgi->param("foo");
This fetches the value of the named parameter. If no argument is given to param(), a list of all parameter names is returned.
$cgi->header($header);
In a mod_perl environment, this sets the headers, whereas in a CGI environment, this returns a string containing the headers to be printed out. If no argument is given to header(), only the Content-Type is set, which by default is text/html. If a hash reference $header is passed to header, such as
my $header = {'Content-Type' => 'text/plain; charset=utf-8', 'X-err_header_out' => 'err_headers_out', };
these will be used as the headers.
my $ip = $cgi->remote_addr();
This returns the remote IP address.
my $url = $cgi->url();
This returns the fully-qualified url, without the query string component.
my $r = $cgi->r;
This returns the Apache2::RequestRec object $r passed into the new() method.
my $req = $cgi->req;
This returns the Apache2::Request object $req, which provides the param() method to fetch form parameters.
SEE ALSO
CGI, Apache2::RequestRec, and Apache2::Request.
Development of this package takes place at http://cpan-search.svn.sourceforge.net/viewvc/cpan-search/CGI-Apache2-Wrapper/.
SUPPORT
You can find documentation for this module with the perldoc command:
perldoc CGI::Apache2::Wrapper
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
CPAN::Forum: Discussion forum
CPAN Ratings
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Apache2-Wrapper
Search CPAN
UWinnipeg CPAN Search
COPYRIGHT
This software is copyright 2007 by Randy Kobes <r.kobes@uwinnipeg.ca>. Use and redistribution are under the same terms as Perl itself; see http://www.perl.com/pub/a/language/misc/Artistic.html.