CGI::Compile - Compile .cgi scripts to a code reference like ModPerl::Registry
use CGI::Compile; my $sub = CGI::Compile->compile("/path/to/script.cgi");
CGI::Compile is an utility to compile CGI scripts into a code reference that can run many times on its own namespace, as long as the script is ready to run on a persistent environment.
NOTE: for best results, load CGI::Compile before any modules used by your CGIs.
Combined with CGI::Emulate::PSGI, your CGI script can be turned into a persistent PSGI application like:
use CGI::Emulate::PSGI; use CGI::Compile; my $cgi_script = "/path/to/foo.cgi"; my $sub = CGI::Compile->compile($cgi_script); my $app = CGI::Emulate::PSGI->handler($sub); # $app is a PSGI application
If your CGI script has a subroutine that references the lexical scope variable outside the subroutine, you'll see warnings such as:
Variable "$q" is not available at ... Variable "$counter" will not stay shared at ...
This is due to the way this module compiles the whole script into a big sub. To solve this, you have to update your code to pass around the lexical variables, or replace my with our. See also http://perl.apache.org/docs/1.0/guide/porting.html#The_First_Mystery for more details.
sub
my
our
Tatsuhiko Miyagawa <miyagawa@bulknews.net>
Rafael Kitover <rkitover@cpan.org>
Hans Dieter Pearcey <hdp@cpan.org>
Copyright (c) 2009 Tatsuhiko Miyagawa <miyagawa@bulknews.net>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
ModPerl::RegistryCooker CGI::Emulate::PSGI
To install CGI::Compile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::Compile
CPAN shell
perl -MCPAN -e shell install CGI::Compile
For more information on module installation, please visit the detailed CPAN module installation guide.