Sunday, December 6, 2009

CGI::Emulate::PSGI error

While working with the code of the previous article, I realized that the example of CGI::Emulate::PSGI wasn't working, because I did not reset CGI's global variables.
Here is the correct way to do it:

1 use CGI::Emulate::PSGI;
2 use CGI;
4 my $app = CGI::Emulate::PSGI->handler(sub {
5     CGI::initialize_globals();
6     do "perldocweb";
7 })


  1. This is already in the documentation for CGI::Emulate::PSGI, and it's been there as long as the code's been on CPAN.

    So, yeah, if you don't do what the docs say, your code doesn't work.

    The docs also (as of yesterday) link to CGI::Compile, which takes care of this for you.

  2. You're right, I edited the post to show that it was my mistake.