in reply to Re^4: Perl CGI -disabled
in thread Perl CGI -disabled

As an aside, I have to ask do you really need to use CGI, and if so is there a reason you're not using some templating mechanism (e.g. HTML::Template/Template)? The reason I ask is that it's no secret that the module itself is quite dated, and can make life really quite difficult for you. The documentation states:

CGI.pm HAS BEEN REMOVED FROM THE PERL CORE

"The rational for this decision is that CGI.pm is no longer considered good practice for developing web applications, including quick prototyping and small web scripts. There are far better, cleaner, quicker, easier, safer, more scalable, more extensible, more modern alternatives available at this point in time. These will be documented with CGI::Alternatives."

Replies are listed 'Best First'.
Re^6: Perl CGI -disabled
by Your Mother (Archbishop) on Sep 23, 2014 at 16:14 UTC

    I understand and I support the removal as a sane way to get Perl out of defaulting to the 90s but it’s not quite fair to say that there are easier alternatives for everything. Yes extensible, scalable, modern, forward-thinking, editable, etc but CGI.pm’s HTML generation and parameter handling is faster and eaiser than templates and I’ll continue to use it in one-offs, helpers, starting or piecing together templates, etc. Knocking this out with a template or a hand rolled .psgi or even mojolicious is more effort. The effort of course may be justified but sometimes it’s all one wants or needs–

    perl -MCGI=:all -E 'say header(), start_html(), h1("OHAI"), start_form(), p(textfield("search")), submit("Go"), end_form(), end_html()'

    Years of really excellent work went into the kit as messy as is it and it can still be a nice tool when not used for things other than the backbone for a “real” application.

      At work I maintain some legacy code which uses CGI and CGI::Application, for both of which I employ a templating system since I find it much easier to work with HTML that way. IMHO it's much easier (and takes less time) to keep HTML/CSS/JS separate from perl code.

        I don’t disagree at all. My job is similar. I am just shy of the pervasive, long term slamming and rooting for round-filing CGI.pm. It’s a valuable tool even though I agree it shouldn’t be on the front lines anymore. I think there would be much less home-rolled parameter handling code in the wild, for example, without the oft shown attitude that CGI.pm is somehow toxic.

      or even mojolicious is more effort.  perl -MCGI=:all -E " say header(), start_html(), h1('OHAI'), start_form(), p(textfield('search')), submit('Go'), end_form(), end_html() "

      I love CGI.pm too, but Mojolicious is just as quick for lots of things :)

      $ mojo generate lite_app RoShamBo.pl [exist] C:\test [write] C:\test\RoShamBo.pl [chmod] RoShamBo.pl 744 $ cat RoShamBo.pl #!/usr/bin/env perl use Mojolicious::Lite; # Documentation browser under "/perldoc" plugin 'PODRenderer'; get '/' => sub { my $c = shift; $c->render('index'); }; app->start; __DATA__ @@ index.html.ep % layout 'default'; % title 'Welcome'; Welcome to the Mojolicious real-time web framework! @@ layouts/default.html.ep <!DOCTYPE html> <html> <head><title><%= title %></title></head> <body><%= content %></body> </html>
      Add a form and
      <h1>OHAI</h1> %= form_for '/' => begin %= text_field 'search' %= submit_button 'Go' % end
      and you're off and running

        Mojolicious is great, especially, in my view, for testing. The equivalent example is *excellent* to include here but please see the irony. The code to point out how easy CGI.pm could be for some things was literally a one-liner. :P