Making Dancer Dance on CGI A.K.A. Blog Fix #543

So, last blog entry I mentioned Dancer and that I want to use it as CGI (since it's Plack-aware) but I don't know how.

Nick Spacek commented on my entry saying that if it supports Plack/PSGI, there should be an easy way to run it as CGI.

Later that evening I sat down for hummus with my girlfriend (hummus is awesome, ok?). After talking to her about it, I decided to take a minute to check online on my phone if anyone has any explanations on it. In the first 5 results, I found a post Alexis Sukriah (who wrote Dancer!) wrote that same day, regarding my post, showing how to use Plack to run a Dancer app under CGI!

Case in point:

use Plack::Server::CGI;
use Plack::Util;

my $psgi = '/path/to/your/app/app.psgi';
my $app = Plack::Util::load_psgi($psgi);
Plack::Server::CGI->new->run($app);

... and the web server configuration to use it.
(example shown on Alexis' post)

And that brings me to a point I forgot to mention in the previous post. Dancer has a very dedicated author, a Github account with lotsa forks and cares very much about community and communal programming. I have to say, that's a major high point in any module/program/framework I want to use.

So, I stand corrected. Plack is awesomer than originally thought.

miyagawa++, sukriah++ :)

4 Comments

A big thank to you for that new blog entry. I'm glad Dancer fits your needs.

Oh, by the way, my name is "Sukrieh" ;-) (and my nickname "sukria", which might be indeed confusing ;-)

We're in the process of renaming Plack::Server::CGI to Plack::Handler because it's not really a Server. Actually, more compatible way to write the CGI script is:

use Plack::Runner;
Plack::Runner->run('/path/to/your/app.psgi');

This automatically detect that it's running under the CGI and auto-dispatch to the current environment. (and actually works as a FCGI script)

Leave a comment

About Sawyer X

user-pic Gots to do the bloggingz