在PSGI中传递变量

时间:2014-09-08 14:25:07

标签: cgi param psgi

我有一个CGI脚本,我想转换为PSGI。这是结果:

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;
});

点击“做某事”后,我会返回同一页面(显然),但应该打印'click_me'。这在CGI中有效,但由于某种原因PSGI没有通过这个变量。我可以打印上面定义的其他变量。所以我的@keys = param();似乎没有做很多。

0 个答案:

没有答案