CGI::PSGI - Enable your CGI.pm aware applications to adapt PSGI protocol
use CGI::PSGI; sub app { my $env = shift; my $q = CGI::PSGI->new($env); return [ $q->psgi_header, [ $body ] ]; }
First of all, if you have a CGI script that you want to run under PSGI web servers (i.e. "end users" of CGI.pm), this module might not be what you want. Take a look at CGI::Emulate::PSGI instead.
This module is for web application framework developers who currently uses CGI to handle query parameters. You can switch to use CGI::PSGI instead of CGI, to make your framework compatible to PSGI with a slight modification of your framework adapter.
Your application, typically the web application framework adapter should update the code to do CGI::PSGI->new($env) instead of CGI->new to create a new CGI object, in the same way how CGI::Fast object is being initialized in FastCGI environment.
CGI::PSGI->new($env)
CGI->new
CGI::PSGI is a subclass of CGI and handles the difference between CGI and PSGI environments transparently for you. Function-based interface like use CGI ':standard' doesn't work with this module. You should always create an object with CGI::PSGI->new($env) and should call a method on it.
use CGI ':standard'
psgi_header method is added for your convenience if your application uses $cgi->header to generate header, but you are free to ignore this method and instead can generate status code and headers array ref by yourself.
psgi_header
$cgi->header
It adds a following extra method to CGI object.
$env = $cgi->env;
Returns PSGI environment hash refernce. This allows CGI.pm based application frameworks such as CGI::Application to access PSGI extension, typically set by Plack Middleware components.
So if you enable Plack::Middleware::Session, your application and plugin developers can access the session via:
$cgi->env->{'plack.session'}->get("foo");
Of course this should be coded carefully by checking the existence of env method as well as the hash key plack.session.
env
plack.session
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.
CGI CGI::Emulate::PSGI
To install CGI::PSGI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::PSGI
CPAN shell
perl -MCPAN -e shell install CGI::PSGI
For more information on module installation, please visit the detailed CPAN module installation guide.