Mojolicious Plackup!
Hi, perl-users.
The past few days, Although I couldn't decide what to write day 23, fortunately, sri added native PSGI support to Mojolicious at 12/16/2009. I decided to write this article of this feature.
So, this year, the most interesting thing in YAPC::Asia 2009 is PSGI/Plack from Miyagawa-san. PSGI is Perl Web Server Gateway Interface Specfication, and Plack is PSGI reference implementation and utilities(I think you know it). For details, go to plackperl.org and Googling around it if you want.
First of all, You install Mojo and Plack. I think it would be better to use local::lib. As for local::lib, Please refer to day 2 by otsune-san. Mojo installation is very easy. Doesn't have any dependency other than Perl 5.8.1.
A word of caution: Do not use Mojo(0.999914) on CPAN in this article. You should install Mojo(0.999915) from github. Only github includes PSGI feature. Not includes it on CPAN now. Sorry, I don't expalin installation process in detail here.
Once those installs are done, generate a mojolicious application. Mojo has a helper script that creates all the working files that you need get started in the directory.
$ ./extlib/bin/mojolicious generate app Centipede
$ ls -al drwxr-xr-x 8 kaz kaz 4096 2009-12-20 22:02 centipede/ # Mojo Application drwxr-xr-x 5 kaz kaz 4096 2009-12-20 21:45 extlib/ # libraries
Once you have generated your application, prepare for the ".psgi". Interestingly, Mojo has a ".psgi" generator.
$ mv centipede/script/ $ ./centipede generate psgi
centipede.psgi
use FindBin; use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/../lib"; use Mojo::Server::PSGI; my $psgi = Mojo::Server::PSGI->new(app_class => 'Centipede'); my $app = sub { $psgi->run(@_) };
Let's plackup!
$ perl -I./centipede/lib ./extlib/bin/plackup -app ./centipede/centipede.psgi
Now we have our standalone server running on port 5000 so browsing:
http://localhost:5000
And will see a welcome message from Mojolicious.
Specifically, I think Mojo::Server::PSGI is NOT server, enables Mojo applications to adapt PSGI protocole like CGI::PSGI.
.----------------. | Mojolicious | '----------------' | .---------. | Mojo | '---------' | .----------------------. | Mojo::Server::PSGI | '----------------------' | .---------. | Plack | '---------' | .----------. | Server | '----------'
Mojo already supports most server environment. Although I think PSGI might not be direct benefit immediately, It is going to get a fast server and useful middlewares near future. I'm looking forward to it.
My English Sux. FIXME.
Next day 24 is aomushi510-san. Don't miss it!
#mojoの人にも読んでもらえらたらなーと思い英語が得意なわけでもないのに英語で書いてみました。英語読みたくない方や間違いだらけで恥ずかしくて読んでいられないというかたはブログに日本語で書くつもりなのでそちらをどうぞ:)