1CGI::Emulate::PSGI(3) User Contributed Perl DocumentationCGI::Emulate::PSGI(3)
2
3
4
6 CGI::Emulate::PSGI - PSGI adapter for CGI
7
9 my $app = CGI::Emulate::PSGI->handler(sub {
10 # Existing CGI code
11 });
12
14 This module allows an application designed for the CGI environment to
15 run in a PSGI environment, and thus on any of the backends that PSGI
16 supports.
17
18 It works by translating the environment provided by the PSGI
19 specification to one expected by the CGI specification. Likewise, it
20 captures output as it would be prepared for the CGI standard, and
21 translates it to the format expected for the PSGI standard using
22 CGI::Parse::PSGI module.
23
25 If your application uses CGI, be sure to cleanup the global variables
26 in the handler loop yourself, so:
27
28 my $app = CGI::Emulate::PSGI->handler(sub {
29 use CGI;
30 CGI::initialize_globals();
31 my $q = CGI->new;
32 # ...
33 });
34
35 Otherwise previous request variables will be reused in the new
36 requests.
37
38 Alternatively, you can install and use CGI::Compile from CPAN and
39 compiles your existing CGI scripts into a sub that is perfectly ready
40 to be converted to PSGI application using this module.
41
42 my $sub = CGI::Compile->compile("/path/to/script.cgi");
43 my $app = CGI::Emulate::PSGI->handler($sub);
44
45 This will take care of assigning a unique namespace for each script
46 etc. See CGI::Compile for details.
47
48 You can also consider using CGI::PSGI but that would require you to
49 slightly change your code from:
50
51 my $q = CGI->new;
52 # ...
53 print $q->header, $output;
54
55 into:
56
57 use CGI::PSGI;
58
59 my $app = sub {
60 my $env = shift;
61 my $q = CGI::PSGI->new($env);
62 # ...
63 return [ $q->psgi_header, [ $output ] ];
64 };
65
66 See CGI::PSGI for details.
67
69 handler
70 my $app = CGI::Emulate::PSGI->handler($code);
71
72 Creates a PSGI application code reference out of CGI code
73 reference.
74
75 emulate_environment
76 my %env = CGI::Emulate::PSGI->emulate_environment($env);
77
78 Creates an environment hash out of PSGI environment hash. If your
79 code or framework just needs an environment variable emulation, use
80 this method like:
81
82 local %ENV = (%ENV, CGI::Emulate::PSGI->emulate_environment($env));
83 # run your application
84
85 If you use "handler" method to create a PSGI environment hash, this
86 is automatically called in the created application.
87
89 Tokuhiro Matsuno <tokuhirom@cpan.org>
90
91 Tatsuhiko Miyagawa
92
94 Copyright (c) 2009-2010 by tokuhirom.
95
96 This program is free software; you can redistribute it and/or modify it
97 under the same terms as Perl itself.
98
99 The full text of the license can be found in the LICENSE file included
100 with this module.
101
103 PSGI CGI::Compile CGI::PSGI Plack CGI::Parse::PSGI
104
105
106
107perl v5.30.1 2020-01-29 CGI::Emulate::PSGI(3)