tags:

views:

311

answers:

7

A few years ago I did a lot of work with CGI.pm. I'm evaluating using it again for a quick project. Can someone bring me up to speed on the current state of developing with CGI.pm in the "Web 2.0" world? What are the best libraries on CPAN to use with it? Are there clean ways to include jQuery, YUI, other CSS libs, etc, and do some AJAX. There are of course lots of libraries on CPAN but what works and what is commonly used?

We aren't still doing this?

$JSCRIPT<<EOF;
...
EOF

I realize people are going to offer Catalyst as an answer. However, many people may have legacy CGI.pm apps they simply want to enhance. Is starting over really the best answer?

+4  A: 

Consider using something more modern, for example Catalyst. It will make your life much easier and you won't have to reinvent the wheel. I understand that it is just a small project, but from my experience many small projects in time become large ones :)

Adam Byrtek
What do you do with legacy apps that already use CGI.pm?
From your initial question I understood that you want to build a new project, not modify a legacy app.
Adam Byrtek
I was trying to offer a reason to get a good answer to my question. There are lots of answers on this site that say use Catalyst. That is really the only game in town? There are Perl jQuery and AJAX libs. Is anything else any good?
@melling - I tend to avoid any Perl jQuery/AJAX modules because at some point u have to get your hands dirty and work with them direct ;-)
draegtun
+2  A: 

It's perfectly possible to write "Web 2.0" apps using CGI.pm, but you'll have to do the work yourself. From what I've seen, the focus in the Perl development community has been on developing successor frameworks to CGI, not on writing helper modules to let legacy apps get bootstrapped into modern paradigms. So you're somewhat on your own.

As to whether to start over, what are you really trying to accomplish? Everyone's definition of "Web 2.0" is somewhat different.

If you're trying to introduce a few modern features (like AJAX) to a legacy app, then there's no reason you need to start over.

On the other hand if you're trying to write something that truly looks, feels, and works like a modern web app (for example, moving away from the page-load is app-state model), you should probably consider starting from the ground up. Trying to make that much of a transformation happen after the fact is going to be more trouble than it's worth for anything but the most trivial of apps.

Adam Bellaire
+1  A: 

I agree with Adam's answer, you probably want to use Catalyst. That being said, if you really don't want to, there's nothing preventing you from using only CGI.pm. The thing is, Catalyst is a collection of packages that do the things you want to make Web 2.0 easy. It combines the various templating engines such as Template Toolkit or Mason with the various ORM interfaces like DBIx::Class and Class::DBI.

Certainly you don't have to use these things to write Web 2.0 apps, it's just a good idea. Part of your question is wondering if javascript and CSS frameworks like jQuery, or prototype require anything from the server-side code. They don't, you can use them with any kind of server-side code you want.

bmdhacks
+1  A: 

If the jump from CGI.pm to Catalyst seems too daunting then perhaps something like Squatting might be more appropriate?

Squatting is a web microframework and I have found it ideal for quick prototyping and for replacing/upgrading my old CGI scripts.

I have recently built a small "web 2.0" app with Squatting using jQuery with no issues at all. Inside the CPAN distribution there is an example directory which contains some programs using jQuery and AJAX including a very interesting COMET example which makes use of Continuity (which Squatting "squats" on by default).

NB. If required then u can later "squat" your app onto Catalyst with Squatting::On::Catalyst

/I3az/

draegtun
Well, my first couple of cracks at installing Catalyst didn't work on Fedora FC9 x64. I did a few simple web reports with CGI.pm this morning. I'll play Catalyst when I've got some time to burn getting it installed.
Catalyst can sometimes be a pain to load sometimes http://draegtun.wordpress.com/2008/06/16/installing-catalyst-on-production-server-yesterday/
draegtun
Squatting is a lot easier to load. However there r (or were) some issues with Coro 4.8 http://groups.google.co.uk/group/squatting-framework/browse_thread/thread/3e879ae9f2e41d7f
draegtun
+2  A: 

The "web 2.0" apps that I've worked with usually use client-side JavaScript to request JSON data from the server, then use that data to update the page in-place via DOM.

The JSON module is useful for returning structured data to a browser.

As far as including JavaScript, HTML, or whatever in a here doc - that was never a good idea, and still isn't. Instead, use one of the plethora of template modules to be found on CPAN. For a CGI, I'd avoid "heavy" modules like Mason or Template Toolkit, and use a lighter module for quicker startup, such as Text::Template, or Template::Simple.

Sherm Pendley
+6  A: 

Personally, I'm no fan of Catalyst (too heavy for my taste) or Mason (mixing code and HTML is bad ju-ju), but I do quite well using CGI.pm for input[1], HTML::Template for output, and CGI::Ajax to provide AJAX functionality where called for.

If you're looking at frameworks, you may also want to consider CGI::Application, which is a widely-used and lighter-weight alternative to Catalyst/Mason.

[1] I can't recall the last time I called anything other than $q->param or $q->cookie from CGI.pm. There are still a lot of tutorials out there saying to use its HTML-generation functions, but that's still mixing code and HTML in a way that's just as bad as using here docs, if not worse.

Dave Sherohman
About [1]: Amen! That debate has been ongoing since CGI.pm was the "new hotness" being proposed as a replacement for cgilib.pl. Obviously, saner heads did not prevail in that argument. :-( Have you tried using CGI::Lite instead?
Sherm Pendley
I've considered switching to CGI::Simple, but wasn't aware of CGI::Lite. I'll have to add that to my list of modules to investigate in my Copious Free Time.
Dave Sherohman
And there is also CGI::Lazy which looks interesting... http://search.cpan.org/dist/CGI-Lazy/lib/CGI/Lazy.pm
draegtun
+2  A: 

Yes, you can write perfect web2.0 web applications WITHOUT using any framework on the server side in any language Perl, Python, Java, etc and WITHOUT using any JavaScript libraries/framework on the client side. The definition of web 2.0 is kind of a loose definition, and I'm guessing by web2.0, you mean Ajax or partial page refresh, then all you would really need is to focus on the following:

  1. Know about the XmlHttpRequest object.
  2. Know how to return JSON object from the server to the client.
  3. Know how to safely evaluate/parse the JSON object using JavaScript and know to manipulate the DOM. Also, at least know about innerHTML. InnerHTML is helpful occasioanally.
  4. Know CSS.

Having said that, it's a lot easier to use some framework on the server side, but not because it's required by web2.0 and it's a lot easier to use some JavaScript on the client like jQuery, mootools, YUI. And you can mix-and-match depends on your needs and your tastes. Most JavaScript provides wrapper around the XmlHttpRequest so that it works across all browsers. No one write "naked" XmlHttpRequest anymore, unless you want to show some samples.

cathat