Web アプリケーションの実行環境がいろいろある今日このごろです。Apache+mod_perl, lighty+fastcgi, CGI, HTTP::Server::Simple, などなど。でも、Web アプリケーションを 各種実行環境の違いを考慮せずに実装したい。そんな思いがこりかたまってできたのが HTTP::Engine です。一度ウェブアプリケーションを実装してしまえば、各種環境で簡単に 実行できるようになるのです。すばらしい。
いつものように CPAN からインストールしてください。 sudo -H cpan HTTP::Engine とかするだけで、OK ですね。
use HTTP::Engine;
HTTP::Engine->new(
interface => {
module => 'ServerSimple',
args => {
host => 'localhost',
port => 1978,
},
request_handler => sub {
my $req = shift;
return HTTP::Engine::Response->new(
status => 200,
body => 'Hello, World',
);
},
},
)->run;
サーバの設定と、リクエストハンドラの coderef を渡すだけです。簡単ですね。
リクエストハンドラは、リクエストオブジェクトをわたされてレスポンスオブジェクトを 返すだけです。
use HTTP::Engine;
HTTP::Engine->new(
interface => {
module => 'FCGI',
args => {
},
request_handler => sub {
my $req = shift;
return HTTP::Engine::Response->new(
status => 200,
body => 'Hello, World',
);
},
},
)->run;
こんな風にしましょう。はい。なかみはほとんどかわってません。module の指定をかえ たのと、args のところの指定をかえただけです。リクエストハンドラのところは同じで いいんです。これが HTTP::Engine のいいところです。
server.modules = (
"mod_access",
"mod_fastcgi",
"mod_accesslog"
)
server.port = 8572
server.document-root = var.CWD
server.errorlog = var.CWD + "/examples/lighty/error.log"
accesslog.filename = var.CWD + "/examples/lighty/access.log"
fastcgi.server = (
"" => (
(
"bin-path" => var.CWD + "/examples/lighty/test_fastcgi.pl",
"socket" => var.CWD + "/examples/lighty/test.socket",
"check-local" => "disable",
"min-procs" => 1,
"max-procs" => 1,
"idle-timeout" => 20,
"bin-environment" => (
"PERL5LIB" => var.CWD + "/lib/"
)
)
)
)
lighty の設定は上記のようにするかんじですね。かんたんです。
Last modified: $Date: 2008-05-22T09:21:23.154313Z $