Hello, I've found out that CGI.pm is no more in the core distribution of Perl. I've also read that there are many better ways to implement a web application, like use Plack, or use CGI::Application, CGI::Snapp, Dancer, Mojolicious... It is also suggested to use templating systems (ok fine, I've used them with CGI.pm).

However, with modern responsive websites I think that CGI.pm is still a great module, so simple to use it that I don't see a reason to move away or use anything else.

You just write an API for the client javascript making an AJAX request and you're all done with something like:

#!/usr/bin/perl use strict; use CGI; use JSON; my $query = new CGI; my $response = whatever(Query=>$query); my $json = JSON->new->utf8(1)->pretty(1)->allow_nonref->encode($respon +se); print $query->header('application/json').$json; sub whatever { # Here you can do REALLY anything, and send back an hash reference }

Do I make it too easy? This is has a flat learning curve too.

Replies are listed 'Best First'.
Re: Is CGI.pm dead?
by Corion (Patriarch) on May 26, 2015 at 11:18 UTC

    From my point of view, CGI.pm is not dead and it can still be conveniently installed and used. It's just not part of the Perl core anymore, but I see that as an upside as that means less ad-hoc modifications to the Perl core by OS vendors. It also allows an actually more frequent release schedule to the module because OS vendors now don't need to "update" the Perl package just to update the CGI package, and all users of CGI have the CGI package installed.

      It also allows an actually more frequent release schedule to the module because OS vendors now don't need to "update" the Perl package just to update the CGI package, and all users of CGI have the CGI package installed.

      CGI.pm has always been installable without needing to upgrade perl package

Re: Is CGI.pm dead?
by Discipulus (Canon) on May 27, 2015 at 08:15 UTC
    I'm not a web guru nor a Perl one, but i have used CGI.pm a lot in the past and i still maintain a little portal using it.
    I feel the need to upgrade to something modern, because there are a lot of good alternatives. But as always speacking of Perl web dev, there is a little misunderstanding.

    There is the protocol and there is the implementation. I suppose that the protocol is dead as idea, but the implementation can be usable, in very short, protected env. As you have shown. I also consider it still valid as html spawner:
    use CGI qw /:html/; my $q = CGI->new; print $q->redirect( 'http://www.perlmonks.org');
    Anyway there are valid reasons to consider CGI dead: look at SawyerX condamning it: CGI.pm must die! and again SawyerX in the interview where he tells about a Lincoln Stein's answer to the previous talk. As SayerX (coauthor of Dancer) said, i'm thankfull to Lincoln Stein, but we lost a lot of time and now we have to look forward: PSGI is the new protocol and Plack it's implementation.

    Notice also, even if i agree with you about CGI as still good module, in the official doc of the module is stated clearly:
    CGI.pm HAS BEEN REMOVED FROM THE PERL CORE .. The rationale for this decision is that CGI.pm is no longer considered + good practice for developing web applications, including quick proto +typing and small web scripts. There are far better, cleaner, quicker, + easier, safer, more scalable, more extensible, more modern alternati +ves available at this point in time. These will be documented with CG +I::Alternatives.
    More on we are told to not use html generation, too...

    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Is CGI.pm dead?
by leej (Monk) on May 28, 2015 at 13:41 UTC

    Here's your simple example implemented using Mojolicious:

    #!perl use Mojolicious::Lite; any '/route_name' => sub { my ( $self ) = @_; $self->render( json => whatever( $self->req->json ) ); }; sub whatever { my ( $request ) = @_; ... } app->start;

    Benefits out of the box: strict and warnings enabled by default, doesn't need a third party webserver in front of it, is persistent (will be 100+ times faster than your CGI script - oh "mod_perl" you say? I thought we were all done?), is utf-8 safe, is cleaner, is easier to test, is none blocking, etc, etc, etc.

    Saying CGI.pm is simple and that by just writing the code you're all done is to forget the amount of faff required in actually running a cgi script, and then even more faff if you want to do anything slightly more complex and scalable with it.

    FWIW CGI.pm is not dead, but i am not accepting any more feature requests for the module, and will not be doing any maintenance except critical bug fixes. Essentially it is "done".

      Essentially it is "done".

      So no CGI v5? Well, I guess the advocates of backward compatibility will be happier. But in any case thank you for taking care of a module that will probably stay with us for a while longer :-)

      BTW, perhaps better terms would be "mature" or even "legacy"...

        Nope, no v5. I'm just about to drop a release on CPAN that basically says "game over" for all but critical issues.
Re: Is CGI.pm dead?
by dsheroh (Monsignor) on May 27, 2015 at 07:24 UTC
    No, it's not dead.

    A lot of people just wish it was. (I am often, but not always, among them.)

A reply falls below the community's threshold of quality. You may see it by logging in.