0

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.

TheChosenOne
  • 705
  • 1
  • 6
  • 14

0 Answers0