mod_perlのハンドラでフォームのパラメータを取得する

Apache2::Requestを使うとCGIモジュールと同じようなparamメソッドが使える。

以下のモジュールを /handler に登録した場合、http://localhost/handler?test1=Hello のようにクエリストリングにつけたパラメータを取得できる。また、パラメータをPOSTした場合も同じように取得できる。

package My::Handler;
use strict;

use Apache2::RequestRec;
use Apache2::RequestIO;
use Apache2::Request;
use Apache2::Const -compile => 'OK';


sub handler : method {
    my ($class, $r) = @_;

    $r->content_type('text/plain');

    my $req = Apache2::Request->new($r);
    print $req->param('test1');

    return Apache2::Const::OK;
}

1;