A Day With Catalyst

You may remember that after the Web Frameworks Evening I rashly proposed that I would develop a simple application with each of the frameworks mentioned. Earlier in the week, as good as my word, I took Catalyst out for a spin.

Out of the three frameworks Catalyst was the one I was most intrigued by. I’ve heard too many people in orange sunglasses rave about Rails for me to get really excited about it. Django is written in my favourite language so it’s going to have to be especially horrid for me not to like it. The idea of a web framework that pulls in all the best tools of the Perl universe peaked my interest sufficiently that Catalyst was the first framework I decided to try.

Now full diclosure time. I’m a bit of a Python bigot, but I thought, how many people learn ruby until they get wowed by Rails? If Catalyst is really good it could bring lots of new people into the Perl community. As a relative Perl newbie I make a good test of that idea. Would I find Catalyst sufficiently awesome that I would consider doing web development in something other than my native language?

perl -MCPAN -e 'install Bundle::Catalyst'

Three hours later after a series of cpan force installs I finally had Catalyst installed and not throwing empty Base Class errors. I know my way around CPAN I suspect the vast majority of people new to Perl don’t. You’ve just lost them.

OK onto the tutorial. It’s pretty good. Writing views is really nice. Dispatching URLs to different functions is dead easy. The debugging output of the test server is massively helpful. Right, onto templates. Hmmm…. OK you can call them explicitly by stashing the template name or it does a clever lookup on the name of the view or the function. Nice. I can see how you don’t need a lot of code to get real functionality out of this. It looks like a simple matter to knock up a function that passes an ID through and uses it for a database lookup. So I really need to move on in the tutorial and work out how to connect to my WordPress db and start grabbing some articles.

Well the tutorial only mentions SQLite while I, and probably 99.9% of the world, am runnnig MySQL. Bit of googling should sort it. OK, no your Base Class is empty? Oh. More google. Aha I can connect now. The test server shows me a class has been created on the fly for each of my tables. The table names match what is in the database so I’m confident it’s actually talking to the DB. Right one line of code is all it should take to get data out. I can pass in a valid ID on the URL and use that to grab a record just like they show in the tutorial. But all I get back out is the ID. More google.

Turns out you don’t get magic relationship mapping out of the box with MySQL and Catalyst::Model::CDBI. There probably is a way to do it but I can’t find any documentation on giving it a relationship map by hand. I’ve now spent nine hours trying to coax this whole thing into life so It’s time to cut my losses and move on.

In short if you are not already a Perl hacker who knows his way aroung Class::DBI or Class::DBIx you may not find Catalyst to your taste. Which is a shame because it has moments of greatnes.

Next time: Django