CGI::Emulate::PSGI - PSGI adapter for CGI
my $app = CGI::Emulate::PSGI->handler(sub { # Existent CGI code, or just: do "script.cgi"; });
This module allows an application designed for the CGI environment to run in a PSGI environment, and thus on any of the backends that PSGI supports.
It works by translating the environment provided by the PSGI specification to one expected by the CGI specification. Likewise, it captures output as it would be prepared for the CGI standard, and translates it to the format expected for the PSGI standard.
If your application uses CGI, be sure to cleanup the global variables in the handler loop yourself, so:
my $app = CGI::Emulate::PSGI->handler(sub { do "script-that-uses-cgi-pm.cgi"; CGI::initialize_globals() if defined &CGI::initialize_globals; });
Otherwise previous request variables will be reused in the new requests.
Alternatively, you can install and use CGI::PSGI from CPAN, but that would require you to slightly change your code from:
my $q = CGI->new; # ... print $q->header, $output;
into:
use CGI::PSGI; my $app = sub { my $env = shift; my $q = CGI::PSGI->new($env); # ... return [ $q->psgi_header, [ $output ] ]; };
See CGI::PSGI for details.
PSGI.
Tokuhiro Matsuno <tokuhirom@cpan.org>
Tatsuhiko Miyagawa
Copyright (c) 2009 by tokuhirom.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
To install CGI::Emulate::PSGI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::Emulate::PSGI
CPAN shell
perl -MCPAN -e shell install CGI::Emulate::PSGI
For more information on module installation, please visit the detailed CPAN module installation guide.