(You are Anonymous)

CGI.pm alternatives for use with CGI::Application

Some people prefer to to use alternatives to "CGI.pm", often on the quest for a performance improvement.

Why ?

The reasoning here is that CGI.pm is a rather heavy module and takes some time to load. Another (more thorough) approach to minimizing startup times is to use a persistent environment such as mod_perl or Fast CGI (see Site Performance). Using either technology lets you load the Perl interpreter and all your modules (not just CGI.pm) just once and keep them in memory between requests.

CGI.pm methods used by CGI::Application

Any replacement module will need to supply the following equivalent functions:

$q->param($name)
CGI->new()      # in cgiapp_get_query, which needs to be over-ridden
$q->redirect(%header_props) 
$q->header(%header_props)
$q->Dump()      # in the dump_html method, plain dump does not need it

Alternatives known to work

The following modules are known to work as replacements for CGI.pm in this capacity:

"Essentially everything in CGI.pm that relates to the CGI (not HTML) side of things is available [in CGI::Simple]. There are even a few new methods and additions to old ones! In practical testing this module loads and runs about twice as fast as CGI.pm depending on the precise task."

Here's how to make the switch:

package YourApp;
use strict;
use base 'CGI::Application';
...
use CGI::Simple;
...
sub cgiapp_get_query {
  my($self) = @_;
  return CGI::Simple -> new();
} 

or

sub cgiapp_get_query { # overrides

require CGI::Simple;  # note, uploads are disabled by default in CGI::Simple
CGI::Simple->new()

}

Caveat

While the light-weight alternatives to CGI.pm mostly do what they claim to do, some other modules that were written for the normal CGI.pm sometimes do not work properly with substitute modules like CGI::Simple. Such problems have been reported with CGI::Simple for example.

Even if the fault lies not with CGI::Simple, but rather with the other module's inflexibility, this is something you have to watch out for. So if you run into strange errors with CGI::Simple and friends, try the same code with CGI.pm to see if the same problem occurs (and if not, kindly ask the authors of the troublesome module if it is not possible to fix things).

Alternative when using mod_perl

Another module to look at when running under mod_perl is Apache::Request. It uses the internal Apache web server API and is thus very fast. While it aims to be compatible with CGI.pm some compatibility is sacrificed for speed. It also does not work out of the box with CGI::Application.

To achieve complete built-in support see CGI::Application::Plugin::Apache.

See Also