develooper Front page | perl.perl5.porters | Postings from May 2013

Re: is dead, long live

Thread Previous | Thread Next
Tatsuhiko Miyagawa
May 28, 2013 11:57
Re: is dead, long live
Message ID:
On Tue, May 28, 2013 at 8:28 PM, Johan Vromans <> wrote:
> Aristotle Pagaltzis <> writes:
> The bottom line is that my CGI solution requires 10-20 lines of code,
> works out of the box on any web host with Perl, without the need for
> additional modules and server (re)configuration.
> I have yet to see Plack code that does the same.

    % cat > app.cgi
    package main;

    my $app = sub {
        return [ 200, [ "Content-Type", "text/html" ], [ "Hello" ] ];

    % cat `perldoc -l Plack::Handler::CGI` app.cgi > app_bundled.cgi

Now app_bundled.cgi works as a CGI script, no dependencies out of the
core (Plack::Handler::CGI only requires and IO::Handle). FTP
that file, chmod +x it and it works as a CGI script on any host.

Although more realistically, take Mojolicious::Lite as an example,
since I want to point out PSGI doesn't really mean Plack and whichever
frameworks that support PSGI can come into play:

    $ cat >
    use Mojolicious::Lite;
    get '/' => sub {
      my $self = shift;
      $self->render(text => "Hi");

The can work as a CGI, but also as a PSGI handler if you
deploy to platforms that only supports PSGI apps and *not* CGI, such
as Heroku, DotCloud and Stackato.

Tatsuhiko Miyagawa

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About