HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/share/man/man3/CGI::Emulate::PSGI.3pm
.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
.    if \nF \{\
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{\
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "CGI::Emulate::PSGI 3"
.TH CGI::Emulate::PSGI 3 "2017-05-08" "perl v5.26.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
CGI::Emulate::PSGI \- PSGI adapter for CGI
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 3
\&    my $app = CGI::Emulate::PSGI\->handler(sub {
\&        # Existing CGI code
\&    });
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This module allows an application designed for the \s-1CGI\s0 environment to
run in a \s-1PSGI\s0 environment, and thus on any of the backends that \s-1PSGI\s0
supports.
.PP
It works by translating the environment provided by the \s-1PSGI\s0
specification to one expected by the \s-1CGI\s0 specification. Likewise, it
captures output as it would be prepared for the \s-1CGI\s0 standard, and
translates it to the format expected for the \s-1PSGI\s0 standard using
CGI::Parse::PSGI module.
.SH "CGI.pm"
.IX Header "CGI.pm"
If your application uses \s-1CGI\s0, be sure to cleanup the global
variables in the handler loop yourself, so:
.PP
.Vb 6
\&    my $app = CGI::Emulate::PSGI\->handler(sub {
\&        use CGI;
\&        CGI::initialize_globals();
\&        my $q = CGI\->new;
\&        # ...
\&    });
.Ve
.PP
Otherwise previous request variables will be reused in the new
requests.
.PP
Alternatively, you can install and use CGI::Compile from \s-1CPAN\s0 and
compiles your existing \s-1CGI\s0 scripts into a sub that is perfectly ready
to be converted to \s-1PSGI\s0 application using this module.
.PP
.Vb 2
\&  my $sub = CGI::Compile\->compile("/path/to/script.cgi");
\&  my $app = CGI::Emulate::PSGI\->handler($sub);
.Ve
.PP
This will take care of assigning a unique namespace for each script
etc. See CGI::Compile for details.
.PP
You can also consider using \s-1CGI::PSGI\s0 but that would require you to
slightly change your code from:
.PP
.Vb 3
\&  my $q = CGI\->new;
\&  # ...
\&  print $q\->header, $output;
.Ve
.PP
into:
.PP
.Vb 1
\&  use CGI::PSGI;
\&
\&  my $app = sub {
\&      my $env = shift;
\&      my $q = CGI::PSGI\->new($env);
\&      # ...
\&      return [ $q\->psgi_header, [ $output ] ];
\&  };
.Ve
.PP
See \s-1CGI::PSGI\s0 for details.
.SH "METHODS"
.IX Header "METHODS"
.IP "handler" 4
.IX Item "handler"
.Vb 1
\&  my $app = CGI::Emulate::PSGI\->handler($code);
.Ve
.Sp
Creates a \s-1PSGI\s0 application code reference out of \s-1CGI\s0 code reference.
.IP "emulate_environment" 4
.IX Item "emulate_environment"
.Vb 1
\&  my %env = CGI::Emulate::PSGI\->emulate_environment($env);
.Ve
.Sp
Creates an environment hash out of \s-1PSGI\s0 environment hash. If your code
or framework just needs an environment variable emulation, use this
method like:
.Sp
.Vb 2
\&  local %ENV = (%ENV, CGI::Emulate::PSGI\->emulate_environment($env));
\&  # run your application
.Ve
.Sp
If you use \f(CW\*(C`handler\*(C'\fR method to create a \s-1PSGI\s0 environment hash, this
is automatically called in the created application.
.SH "AUTHOR"
.IX Header "AUTHOR"
Tokuhiro Matsuno <tokuhirom@cpan.org>
.PP
Tatsuhiko Miyagawa
.SH "COPYRIGHT AND LICENSE"
.IX Header "COPYRIGHT AND LICENSE"
Copyright (c) 2009\-2010 by tokuhirom.
.PP
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
.PP
The full text of the license can be found in the
\&\s-1LICENSE\s0 file included with this module.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\s-1PSGI\s0 CGI::Compile \s-1CGI::PSGI\s0 Plack CGI::Parse::PSGI