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'.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|