Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jozef (8299)

  (email not shown publicly)

Journal of jozef (8299)

Tuesday February 26, 2008
03:24 PM

Catalyst book review

[ #35772 ]

Accelerating Perl Web Application Development

A new book promising to teach:

  • Installing and setting up Catalyst
  • Using the Template toolkit to generate HTML output
  • Designing, accessing and working with databases
  • Using FormBuilder fto define auto-generating and self-validating forms
  • Using the session plug-in to add sessions to an application
  • Authentication and authorization, explored by implemented page-level and record-level control
  • Interfacing to your data
  • Adding REST API, AJAX interactivity, RSS feeds in your application
  • Automated testing and the "Test-Driven Development" methodology, discussed in depth
  • Writing tests for applications developed in this book with MEchanize and Selenium
  • Packaging you application

Quite a lot of topics for a 180 page work. But it's the first book for Perl about modern "hot" web stuff. The author of this book is Jonathan Rockway a member of the Catalyst Core Team.

The book it self is too short to go much deep into to the topics but shows a whole picture about Catalyst and the modules that are needed to make the web application work. The book contains a lot of information regarding the framework and I learned a few things that I couldn't found on CPAN. Here they are:

(p. 41) I found the usage of use base Catalyst::Controller::BindLex practical. Using it you don't have to manually put variables to the stash. Instead a simple my $var : Stashed = 'foo'; will automatically declare and propagate a variable to the stash.

(p. 45) There were more interesting things about DBIx::Class. For instance, the method ->find_or_new() which will either find the row in the database of create a new object. Another example is when properties are set/updated, calling ->update_or_insert() it, as it names implies, will insert or update the record into the database. This little neat tricks will reduce the amount of duplicated code.

(p. 66) I found out that ResultSet has a "build-in" pager: ->page(1), ->pager;

(p. 96) Jonathan was doing "magic" with resultsets, specially showing us how we can chain them and how to use ->search_related()

Reading this book made me realize that DBIx::Class deserves a book on it self. With a complete database design tutorial, examples, reasoning and best practices. With all this topics the book will easily make another 180 pages.

The examples in the book use FormBuilder to setup their forms. From what I have read, it looks like a powerful module. Specially that it's able to generate client side Java Script to validate forms. But this is not described too much in detail.

(p. 54) Regarding YAML and other types of configuration modules you can read only with all the other things. I found two things that can be done quite elegantly. The first is, if we want to pass certain configuration parameters to a model we can just create a configuration section that has the same name as the model to configure (ex. MyApp::DB) and all the variables in the configuration section will be accessible by $self->{key} in that particular model. Quite handy for passing database connection options for example.

(p. 162) The second thing, probably more interesting is that for a given main config file (ex. myapp.yml) we can create a second one with a the suffix '_local' (ex. myapp_local.yml). When this is done, the key-values from the '_local' are added/replaced to the main config file. Thus, we can have the defaults in the main and all the local "diverts" in the "local" without any fear of loosing configuration parameters when upgrading the application. In the past I created a module for this sole purpose.

(p. 57) A small but handy trick is __PACKAGE__->config( 'session' => { 'flash_to_stash' => 1 } ). If we turn on this feature all flash variables can be accessed like ordinary stash variables. Their special "flash" behaviour persists. Not writing ugly conditions, just like I did in the past :$.

And the last thing - is that REST and Jemplate used together will make AJAX. REST was quite interesting for me because it is using the HTTP protocol (GET, PUT, POST, DELETE) for remote communication. Nothing "new" but easy to debug and to use. The preferred content type can be set through HTTP headers (XML, JSON, YAML, ...). JSON's format can be easily used in AJAX for communication with a server. The folks that like using Template Toolkit, will like Jemplate as well. Jemplate uses TT format and prepares the templates for a Java Script on the client side. The TT files can be easily used for both static pages and AJAX part. Very clever and nice too!

I missed some intro to scaffolding which is a pride of Ruby on Rails. There are Catalyst::Helper classes that can do this but I had a bad luck when searching for help or tutorial about them (and this time I was too lazy to read the sources...).

I would appreciate a deeper Catalyst application design analysis. It's one thing to do short examples for a book and another one to start a big project with a good model.

To conclude. A good book, that's easy to read and that's worth to read when you think about WEB 2.0 and Perl. I hope there will be more books of the kind in the market!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Thanks for the review. I agree that DBIx::Class could use its own book. I'm trying to talk Matt Trout into writing one :)
  • The author of this book is Jonathan Rockway the "father" of the Catalyst framework.

    With all due respect to Jonathan, I don't see how he could be considered the "father" of Catalyst. It was originally sri's baby.