Randy Kobes (contact brian d foy) > CGI-Apache2-Wrapper-0.215 > CGI::Apache2::Wrapper

Download:
CGI-Apache2-Wrapper-0.215.tar.gz

Dependencies

Annotate this POD (1)

Website

Related Modules

Apache2::Ajax
Apache::test
Compress::Zlib
Digest::MD5
File::Spec
CGI::Ajax
Test::Pod
Apache::Test
more...
By perlmonks.org
View/Report Bugs
Module Version: 0.215   Source  

NAME ^

CGI::Apache2::Wrapper - CGI.pm-compatible methods 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 certain methods, such as param() to fetch parameters. 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 various CGI.pm-compatible methods via mod_perl2 and librapreq2, and as such, it may be a viable alternative in a mod_perl scenario.

Note that this module is not a drop-in replacement for CGI.pm, as only a select few methods that naturally arise in mod_perl2 and libapreq2 are provided. As well as providing CGI.pm-compatible methods to other modules, one of the main intents here is to assist development of porting CGI applications over to mod_perl2 and libapreq2 and/or for use in writing applications that are to be used in either a cgi or mod_perl environment. However, for applications that are intended only for mod_perl, it is recommended that the native interface to mod_perl2 and libapreq2 ultimately be used, as this module will add some overhead.

Methods ^

Methods are called via the object created as

  my $cgi = CGI::Apache2::Wrapper->new($r);

The Apache2::RequestRec object $r must be passed in as an argument.

Methods available can be grouped according to what mod_perl2/libapreq2 modules provide them:

Apache2::RequestRec

Apache2::RequestUtil

Apache2::Access

Apache2::Connection

Apache2::Request

Apache2::URI

Apache2::Cookie

A new cookie can be created as

 my $c = $cgi->cookie(-name    =>  'foo',
                      -value   =>  'bar',
                      -expires =>  '+3M',
                      -domain  =>  '.capricorn.com',
                      -path    =>  '/cgi-bin/database',
                      -secure  =>  1
                     );

which is an object of the CGI::Apache2::Wrapper::Cookie class. The arguments accepted are

A value of an existing cookie can be retrieved by calling cookie without the value parameter:

   my $value = $cgi->cookie(-name => 'fred');

A list of all cookie names can be obtained by calling cookie without any arguments:

  my @names = $cgi->cookie();

See also CGI::Apache2::Wrapper::Cookie for a CGI::Cookie-compatible interface to cookies.

Apache2::Upload

Uploads can be handled with the upload method:

   my $fh = $cgi->upload('filename');

which returns a file handle that can be used to access the uploaded file. If there are multiple upload fields, calling upload in a list context:

  my @fhs = $cgi->upload('filename');

will return an array of filehandles. There are two helper methods available for uploads:

Helpers

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:

ENVIRONMENT VARIABLES ^

If the USE_CGI_PM environment variable is set, the new method will return a CGI.pm object.

BUGS ^

Although the methods provided here have a natural correspondence with the associated methods of CGI.pm, there may be subtle differences present.

Please report any bugs and feature requests to the author or through CPAN's request tracker at http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Apache2-Wrapper.

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.

syntax highlighting: