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'.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.