スタイルのアドバイス:変数に0または1を割り当てる必要はほとんどありません。ブールコンテキストで値自体を評価するだけです。
CGI.pm (CGI)では、param
メソッドはPOSTパラメーターとGETパラメーターをマージするため、リクエストメソッドを個別に検査する必要があります。
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use CGI qw();
my $c = CGI->new;
print $c->header('text/plain');
if ('POST' eq $c->request_method && $c->param('dl')) {
# yes, parameter exists
} else {
# no
}
print 'Do not taunt happy fun CGI.';
Plack :: Request(PSGI)を使用すると、混合インターフェース( )に加えて、POST(body_parameters
)とGET( )に異なるメソッドがあります。query_parameters
parameters
#!/usr/bin/env plackup
use strict;
use warnings FATAL => 'all';
use Plack::Request qw();
my $app = sub {
my ($env) = @_;
my $req = Plack::Request->new($env);
if ($req->body_parameters->get_all('dl')) {
# yes
} else {
# no
}
return [200, [Content_Type => 'text/plain'], ['Do not taunt happy fun Plack.']];
};