1CGI::PSGI(3)          User Contributed Perl Documentation         CGI::PSGI(3)
2
3
4

NAME

6       CGI::PSGI - Adapt CGI.pm to the PSGI protocol
7

SYNOPSIS

9         use CGI::PSGI;
10
11         my $app = sub {
12             my $env = shift;
13             my $q = CGI::PSGI->new($env);
14             return [ $q->psgi_header, [ $body ] ];
15         };
16

DESCRIPTION

18       This module is for web application framework developers who currently
19       uses CGI to handle query parameters, and would like for the frameworks
20       to comply with the PSGI protocol.
21
22       Only slight modifications should be required if the framework is
23       already collecting the body content to print to STDOUT at one place
24       (rather using the print-as-you-go approach).
25
26       On the other hand, if you are an "end user" of CGI.pm and have a CGI
27       script that you want to run under PSGI web servers, this module might
28       not be what you want.  Take a look at CGI::Emulate::PSGI instead.
29
30       Your application, typically the web application framework adapter
31       should update the code to do "CGI::PSGI->new($env)" instead of
32       "CGI->new" to create a new CGI object. (This is similar to how
33       CGI::Fast object is initialized in a FastCGI environment.)
34

INTERFACES SUPPORTED

36       Only the object-oriented interface of CGI.pm is supported through
37       CGI::PSGI.  This means you should always create an object with
38       "CGI::PSGI->new($env)" and should call methods on the object.
39
40       The function-based interface like "use CGI ':standard'" does not work
41       with this module.
42

METHODS

44       CGI::PSGI adds the following extra methods to CGI.pm:
45
46   env
47         $env = $cgi->env;
48
49       Returns the PSGI environment in a hash reference. This allows
50       CGI.pm-based application frameworks such as CGI::Application to access
51       PSGI extensions, typically set by Plack Middleware components.
52
53       So if you enable Plack::Middleware::Session, your application and
54       plugin developers can access the session via:
55
56         $cgi->env->{'plack.session'}->get("foo");
57
58       Of course this should be coded carefully by checking the existence of
59       "env" method as well as the hash key "plack.session".
60
61   psgi_header
62        my ($status_code, $headers_aref) = $cgi->psgi_header(%args);
63
64       Works like CGI.pm's header(), but the return format is modified. It
65       returns an array with the status code and arrayref of header pairs that
66       PSGI requires.
67
68       If your application doesn't use "$cgi->header", you can ignore this
69       method and generate the status code and headers arrayref another way.
70
71   psgi_redirect
72        my ($status_code, $headers_aref) = $cgi->psgi_redirect(%args);
73
74       Works like CGI.pm's redirect(), but the return format is modified. It
75       returns an array with the status code and arrayref of header pairs that
76       PSGI requires.
77
78       If your application doesn't use "$cgi->redirect", you can ignore this
79       method and generate the status code and headers arrayref another way.
80

LIMITATIONS

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

AUTHOR

87       Tatsuhiko Miyagawa <miyagawa@bulknews.net>
88
89       Mark Stosberg <mark@summersault.com>
90

LICENSE

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

SEE ALSO

96       CGI, CGI::Emulate::PSGI
97
98
99
100perl v5.30.0                      2019-07-26                      CGI::PSGI(3)
Impressum