VOOZH about

URL: https://manpages.org/cgipsgi/3

⇱ man CGI::PSGI (3): Adapt CGI.pm to the PSGI protocol


CGI::PSGI(3) Adapt CGI.pm to the PSGI protocol

SYNOPSIS


use CGI::PSGI;
my $app = sub {
my $env = shift;
my $q = CGI::PSGI->new($env);
return [ $q->psgi_header, [ $body ] ];
};

DESCRIPTION

This module is for web application framework developers who currently uses to handle query parameters, and would like for the frameworks to comply with the protocol.

Only slight modifications should be required if the framework is already collecting the body content to print to at one place (rather using the print-as-you-go approach).

On the other hand, if you are an ``end user'' of .pm and have a script that you want to run under web servers, this module might not be what you want. Take a look at CGI::Emulate::PSGI instead.

Your application, typically the web application framework adapter should update the code to do instead of to create a new object. (This is similar to how CGI::Fast object is initialized in a FastCGI environment.)

INTERFACES SUPPORTED

Only the object-oriented interface of .pm is supported through This means you should always create an object with and should call methods on the object.

The function-based interface like does not work with this module.

METHODS

adds the following extra methods to .pm:

env

 $env = $cgi->env;

Returns the environment in a hash reference. This allows .pm-based application frameworks such as CGI::Application to access extensions, 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 method as well as the hash key .

psgi_header

 my ($status_code, $headers_aref) = $cgi->psgi_header(%args);

Works like .pm's header(), but the return format is modified. It returns an array with the status code and arrayref of header pairs that requires.

If your application doesn't use , you can ignore this method and generate the status code and headers arrayref another way.

psgi_redirect

 my ($status_code, $headers_aref) = $cgi->psgi_redirect(%args);

Works like .pm's redirect(), but the return format is modified. It returns an array with the status code and arrayref of header pairs that requires.

If your application doesn't use , you can ignore this method and generate the status code and headers arrayref another way.

LIMITATIONS

Do not use CGI::Pretty or something similar in your controller. The module messes up 's autoloader and breaks (and potentially other) inheritance.

AUTHOR

Tatsuhiko Miyagawa <[email protected]>

Mark Stosberg <[email protected]>

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.