http://qs1969.pair.com?node_id=1099866

TheChosenOne has asked for the wisdom of the Perl Monks concerning the following question:

I've got a CGI script that I want to convert to PSGI. This is the result:
use CGI::Emulate::PSGI; use strict; use warnings; use CGI qw(:cgi-lib :standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); my $q = new CGI; my @keys = param(); my $state = ""; if(scalar @keys > 0){ $state = $keys[0]; } my $app = CGI::Emulate::PSGI->handler(sub { @keys = $q->param(); print $q->header; print "<center>"; print $q->h1('Some title'); print "</center>"; print $q->start_html(-title => 'Some title'); print $keys[0]; home(); sub home{ print "<center>"; print $q->h3('Pick an option.'); print $q->end_form; print "</center>"; print "<center>"; my $q0 = new CGI; print $q0->start_form( -name => 'some_button', -method => 'POST', -enctype => &CGI::URL_ENCODED, ); print $q0->submit( -name => 'click_me', -value => 'Do something', ); print $q0->end_form; print "</center>"; } print $q->end_form; });
After I click on 'Do something', I return to the same page (obviously), but it should print 'click_me'. This worked in CGI, but for some reason PSGI doesn't pass this variable. I can print other variables that are defined above. So my @keys = param(); doesn't seem to do a whole lot. Edit: Apparently PSGI uses %ENV, but I can't make it work with POST. It works with GET.

Edit: The solution is actually very easy. 'Your Mother' has the solution. I knew that you could compile your CGI scripts and emulate them. But if your run a perl server (like plackup), you get the next error: plackup: Variable "$variable" is not available at /location/of/script." The solution is to change the permissions of all global variables from 'my' to 'our'.