October 22, 2008

Using Catalyst to Develop Web Applications

Filed under: Catalyst, Perl, Programming, Projects — mbeihoffer @ 12:04 pm

I’ve recently been honing my chops with Perl’s Catalyst framework; working my way through the tutorials, reading the module documentation, creating sample applications, and whatnot. The framework has a steep (for me, at least) learning curve, but I believe that overall it will improve my productivity and increase the maintainability of my web applications.

When you create a skeleton application, the framework installs the core MVC modules under your project directory, and it includes a web server built right in to the application, so you can launch the app right away without having to configure Apache’s mod_perl or fastcgi. It’s really nice to have the server open in a console window while you’re serving the site so you can see the stack trace and server responses while you’re browsing the site on the same system.

Catalyst also includes support for user authentication and authorization, so you can plug in those modules and get started on your application without having to worry about how you’re going to secure your application or get user logins working. It also supports form validation through the FormValidator plugin, which makes validating user input a breeze, which is an enormous timesaver over the old ways of doing form validation.

The manual is extensive, with a ten chapter tutorial included, so you can follow along and build the sample application yourself, which is quite helpful in understanding how the framework organizes all the files in your application. You can check the code for the tutorial out from a Subversion repository, which is nice if you’re not interested in doing a lot of typing.

I’m still learning Catalyst, so I’m not really the best person to ask about maintaining applications with it, but so far, it’s been fascinating to learn and I’m eager to get started on a live application soon for one of our new domains. We’ve just registered five more domain names, and I don’t know what we’re going to do with a few of them yet, but they’re registered for three years so hopefully we’ll have time to get a few things up and running, and I plan to use Catalyst to launch sites based on custom code.

Ruby on Rails, Django, Symfony, and CakePHP are all good alternatives to Catalyst, if Perl isn’t your language of choice, but as for myself, I personally have a lot invested in my Perl education and I’d like to be able to write web applications in the language I’m most comfortable with. I don’t mind PHP that much, so I tinkered with Symfony and CakePHP a bit this summer, and Ruby is very interesting to me, but I don’t have much experience with Ruby, so I think using Perl will be faster and more productive for me personally.

PHP is certainly a popular option these days, but I’m not a huge fan of it so far for serious coding, although I’m not opposed to giving it a shot now that PHP5 has decent object support built-in.

In short, Catalyst supplies the die-hard Perl coder with a great MVC framework similar to Ruby on Rails, with access to a large library of modules and plug-ins, and excellent flexibility in terms of what you decide to use for a Model. The tutorial uses SQLite for the examples, but MySQL and PostgreSQL are supported as well, and since the Model is abstracted out of the application, it should make it easy to change database back-ends if you don’t like SQLite or want to support multiple kinds of database for your application.

One thing I haven’t yet tried to accomplish is to get a Catalyst application running under an Apache VirtualHost, which would be ideal as that’s what we run on our web server. I’m sure it won’t be too problematic, but you never know. Perhaps that’s what I should do next, before I start coding an application in earnest, before I get to the stage of launching the application and realize I have no idea how to get it to run under Apache VirtualHosts.

Wish me luck!