Getting rid of CGI.pm in Dancer’s code

Yes, I finally took the decision to stop using CGI.pm in Dancer‘s code. It was not an easy decision to take, mainly because of the following reasons:

  • it’s in the core (I’m a “less-CPAN-deps-ships-better” freak when it’s about Dancer!)
  • it provides a stable and well-known way of dealing with the HTTP interface (params, methods, path infos …)
  • and well, to add a third reason, why should I want to change it if it works?

Well, actually, we did find a bug recently in CGI::PSGI that prevented a Dancer app from being deployed under Plack::Server::Apache2. Oh, of course, the bug was almost instantly fixed when it has been discovered (the #plack people are really reactive).

But that enlightened something: CGI.pm is old, really old, and that means, when you’re using it, you take with you a lots of lines of code coming from years ago. Moreover it is well known that CGI.pm does addresses different matters, such as providing a request interface and generating HTML content as well. Conceptually, it sucks.

After thinking about all that, I decided to drop CGI.pm out of Dancer’s code. I then have the option to use the pretty fresh Plack::Request interface. It looks really nice and does exactly what you can expect from it.

But, it’s important for me that Dancer can be used without Plack. I want the dependency barrier to be as low as possible:
If a user wants to test Dancer, he should not have to install Plack in my opinion. If he likes it, and wants to goes on production, then yes, Plack is a must-go. He then installs Plack and goes on with Dancer’s app.psgi.

So depending on Plack::Request was one more dependency I’d rather not add to Dancer.

With all this in mind I came to the decision to write Dancer::Request, reading carefully the PSGI specs (miyagawa++ again).

It was all good except for processing the POST data. There’s so much work to do when it’s about multipart form, url-encoded form, or even file uploads that I chose not to push the “reinvent-the-wheel” thing too far, and I decided to copycat Plack::Request on this topic: using HTTP::Body.

This module does the job pretty well, with an object-oriented interface.

The conclusion might look like a failure (I rewrote something that worked by adding a new dependecy.) But deep inside I’m happy with this refactoring; because Dancer is now on a way where all of its code will be fresh, based on PSGI specs and won’t ever rely on CGI.pm to do something.

I hope Dancer’s users/developers will agree with that. feel free to comment on this post if you want to share your point of views. Yes, I know this might trigger a troll or two… ;)

4 responses to “Getting rid of CGI.pm in Dancer’s code

  1. Jury Gorky

    CGI::Simple? Yes, it’s a dependency, but it’s a good module I think.

  2. good.
    I switched from perlbal to plack as my app server. No compilation error in new version working with plack.
    plack is great, dancer too!

  3. ImaginaryRobot

    Another alternative would be CGI::Minimal :
    http://search.cpan.org/~snowhare/CGI-Minimal-1.29/lib/CGI/Minimal.pod

  4. Indeed, CGI::Minimal looks good and looks like not dependending on any other module, might be interesting to look at

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Adobe Flash playerPlugin by wpburn.com wordpress themes