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

Re: CGI.pm is dead, long live CGI.pm

Thread Previous | Thread Next
From:
Tatsuhiko Miyagawa
Date:
May 28, 2013 11:57
Subject:
Re: CGI.pm is dead, long live CGI.pm
Message ID:
CADGpoaNQWYrUtfbz7eMTAc+Ve25H8PbCX-XgpSe9Fh+VQonUvA@mail.gmail.com
On Tue, May 28, 2013 at 8:28 PM, Johan Vromans <jvromans@squirrel.nl> wrote:
> Aristotle Pagaltzis <pagaltzis@gmx.de> 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" ] ];
    };
    Plack::Handler::CGI->new->run($app);

    % 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 strict.pm 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 > myapp.pl
    use Mojolicious::Lite;
    get '/' => sub {
      my $self = shift;
      $self->render(text => "Hi");
    };
    app->start;

The myapp.pl 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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About