Book Review: Catalyst 5.8: The Perl MVC Framework

Disclaimer: I was contacted by Packt Publishing about reviewing this book and was sent a free copy to do so.

Background

A long time ago in a land far far away (2004), I started programming in Perl as my non-MS language of choice. It all started innocently enough by taking over others’ CPAN dists, then eventually creating my own shopping cart system intertwined with Catalyst 5.6/5.7 and DBIx::Class.

Then a few years ago as more and more Rails opportunities came along and as ASP.NET MVC 1.0 came into existence, I slowly migrated away from Perl as my primary language. This review is primarily from the perspective of someone who is still fairly familiar with most of Catalyst and while I’m familiar with what Moose has to offer, I haven’t ever done any projects that make use of it.

Enough about me. On with the show!

The Good

This book does a pretty good job of covering all of the basics for people new to Catalyst from installation and app creation to using the most common ORM (DBIX::Class), testing and deployment. There always seems to be a debate about what examples books should use for beginners: best practices vs. simple examples. This book does a pretty good job of finding that middle ground in that area. For example, some of the templating examples aren’t the greatest when it comes to reuse, but the prevention of XSS and security/html encoding are explained fro the beginning.

I’m also fond of this books treatment of models. While it doesn’t explicitly mention “domain model” vs. “data model” arguments, it does a great job of having the user think about having their “models” be reusable and working outside of Catalyst (like in a pl script) before applying “glue” to use those models inside of Catalyst. This is reinforced by creating a few utility scripts to prepopulate the database with data before using that data in Catalyst itself as well as creating non database models for use as Catalyst “models”.

This book spends a fair amount of time talking about the most common features of DBIx::Class as well as presenting options to do the same things in DBI without an ORM for contrast. This book feels like it’s really 35% of a DBIx::Class book. I think that’s a good thing.

Another good area for me was Authentication/Authorization. Those two things aren’t the same and a lot of framework book gloss over that fact. This book did a good job of explaining the difference and showing how to implement each part.

One of my favorite chapters of the book was the “Hot Web Topic” area which covered REST  and AJAX. While most people are familiar with these things, it’s nice that a beginners book covers them. My favorite nugget though is Jemplate, which allows you to essentially reuse templates from your views within your AJAX handlers. While everyone seems to talk about AJAX, I’ve not seem too many people take up the topic of templating your dynamically generated HTML for the sake of DRY.

Last but not least, it’s always nice to be able to download the source code for the examples included in the book.

The Bad

Like all books, there are some things that feel like they were glossed over for the sake or brevity that would’ve have made for a more complete book for Catalyst beginners.

First, in the tempting examples, this book uses an admittedly “unsupported” module called TTSite, which have the common header/footer/wrapper type issues already implemented. I think it would have been better to walk users through setting up those things using the default view and the wrapper options in Template Toolkit.

This is a minor nit and not really a bad thing, but it would’ve been nice for the book to talk a little more about the use of go() vs forward() when transferring between actions.

My last complaint is one of linking to CPAN. CPAN modules often change hands or are updated by many people. Almost all of the links to CPAN in this book link to a specific persons account when they should probably be linking to the dist instead:

# Current

http://search.cpan.org/~bobtfish/Catalyst-Action-REST-0.85/

# Better

http://search.cpan.org/dist/Catalyst-Action-REST-0.85/

The Ugly

The worst part about this book for me was the code formatting. The wrapping of long lines isn’t very readable and for the most part it feels like someone formatted code using Microsoft Word. I haven’t ready any other Catalyst books for comparison, but the code formatting in my Rails books are much easier on the eyes to read. I don’t know if that’s due to language differences, color/font choices, or if maybe putting the code inside of images would help.

Conclusions

Without having read other Catalyst books, I do think this book is a good resource for beginners of Catalyst MVC development. People already familiar with an older version of Catalyst might not find too many surprises, but there are a few nuggets of information about Catalyst+Moose and a good overview of DBIx::Class to refresh your brain.

Posted in Reviews | Leave a comment

Clerbtime & Moving Forward

Had another great time at the Clerb “south” Meetup tonight in Akron hosted by Blue Frog Gaming. Always nice to see more locals at every new meetup. Beers and such afterwords doesn’t hurt either.

Going to these meetups are always humbling. I always leave feeling like I know nothing, but they also provide good motivation to learn something new. It also highlights how much people can do in a day and how much I’m not getting things done. I need to fix that somehow. Too much to learn and do. Too much opportunity being missed.

Things I would like to accomplish in the next 180 days (in no certain order):

  • Rework JanKenPon
  • Make JanKenPon a Facebook App
  • Finish HelpNear.Me Web/iPhone version
  • Get an iPad :-)
  • Make an iPhone/iPad game (HTML5?): Dock Crane Madness
  • Rebrand my blog/logo/cards

Nothing there is terribly difficult. I just need to sack up and do it. For rizzle.

Posted in Events | 1 Comment

Advance2030 Weekend

This last weekend, I was fortunate enough to attend the Advance2030 Web Development Weekend held on the LeanDog boat and spend some time with a great bunch of web folk from the area. This included sitting next to Joe Fiorini and Nate Klaiber and getting schooled in Rails on a nonstop basis. While the weekend was a great experience, I wanted to get some thoughts up about it while they’re still fresh.

Friday night was a great start. After a group gathering to go over the site, we split up into pairs to get a set of story cards created. This was a relatively new experience for me in terms of planning a development cycle.  After tinkering with Cucumber over the last month, it seems to fit right into the Agile/BDD way and it’s something that certainly helps me focus on knowing what I plan on doing before I start coding.

Saturday was a different story. I literally spent the first 5 hours or so struggling with the Rails environment chosen for the weekend. I’m no Rails expert and I understand why some gems were chosen, like Bundler in a forward looking approach to the impending Rails3 release.  But it seems a few of us had issues with it in combination with Authlogic because of which gems loaded first and if we had previously installed any gems using sudo instead of installing them into local gems. When it’s all said and done, I could run rake spec but Command-R in Textmate never worked right. Even after moving on I spent a lot of time dealing with schema.rb merge conflicts when pulling from upstream. This isn’t a terribly surprise given that file is a bottleneck of sorts when you have a lot of people adding migrations in rapid fire.

All in all, I got nothing done Saturday and I’m not proud of it. I lost my will to live at around 3PM. If I were to start an event like this, I would give serious thought to removing some of these pain points for the developers, esp for people who aren’t Rails experts. Stick to the stock Rails gem management setup. The less gems you load, the less shenanigans you have to fight, esp ones that try and manage gems/paths. At list for the first iteration. Also, I would either get the migrations/schema done before the event, or at least funnel migration creation through 1-2 people. Let everyone else mock their way down from the outside in.

Sunday was awesome. I did what I should’ve done Saturday. Grab a card and get something out the door and stop worrying if I’m doing it “right” the first time. It’s easier to re-factor than it is to create. Move forward. By the end of the night I managed to get a calendar page up, styled with the help of Parag including next/previous and month dropdown selection support.

I’m definitely looking forward to the next event like this. Hopefully by then I can get my current Rails project done so I won’t suck so much at the next event. :-)

Posted in Events | 6 Comments

WebFormViewEngine Path Defaults Seem Broken

This post is about 60% fact and 40% opinion. Not a bad ratio. I’ve been working a lot in ASP.NET MVC lately building up a set of classes to be reused across multiple sites in the near future. A few of these legos are small view classes that inherit from WebFormViewEngine. They all do small things, like adding additional file search paths, loading views from resources and fetching views from remote storage. Since you can stack view engines in ViewEngines.Engines, you can add and number of these engines together to get the functionality you want on a site per site basis. First engine to claim it can service a view wins. Nothing special there really.

I stumbled across something today that seems obvious in retrospect that leads me to the opinion that the default view/partial view search patterns are broken. If you crack open Reflector.NET and point it towards WebFormViewEngine, you’ll see that ViewLocationFormats and PartialViewLocationFormats are declared the same:

~/Views/{1}/{0}.aspx
~/Views/{1}/{0}.ascx
~/Views/Shared/{0}.aspx
~/Views/Shared/{0}.ascx

In other words, for the Index action on the Home controller, the following paths are searched:

~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx

This all seems well and good until you happen to have a partial view that has the same name as an action that either happens to be shared, or the parti is being overridden in the local controllers folder. Here’s a somewhat plausible example: A Search controller with an Items action:

~/Views/Search/Items.aspx
    (the view page for the Items action)
~/Views/Home/Index.ascx
    (possibly an items partial view customized just for this controller/action)
~/Views/Shared/Items.ascx
    (the shared partial view to render items in many controllers/actions/views)

This is where the problems start. By default, a call to RenderPartial("Items") within the Items.aspx page is going to find the Items.aspx file first and not the Items.ascx. I’ve never ever seen anyone in the wild put partial views in an aspx file nor have I ever seen anyone put a full action view in an ascx file. So why on earth did they all them to be interchangeable in the location paths? Broken I say. Broken.

The good news is that it’s super easy to tweak these kinds of things in ASP.NET MVC. Inherit from WebFormViewEngine and set your own ViewLocationFormats and PartialViewLocationFormats. I my case I decided to force the issue explicitly. ViewLocationFormats only looks for aspx files and PartialViewLocationFormats only look for ascx files. Now we can override shared partial views locally in controller folders without worrying about name collisions.

Posted in Microsoft | Comments Off

Template Toolkit for .NET

A while back I got the urge the waste time on yet another project. This time, it’s a version of Template Toolkit for .NET. As usual, you can find the project on GitHub.

Not knowing anything about what it takes to convert a template language to .NET I started from ground up learning how to use ANTLR to create a lexer/parser automatically from a grammar definition. As if that wasn’t enough, my parser output is an Abstract Syntax Tree, which I then use another grammar to template it into C# code using StringTemplate templates, which ANTLR supports natively.

It’s slow going, but I’m learning a lot along the way. At some point I’m going to output VB.NET and it still needs a lot of work for compilation, dll caching and such. The code is in a pre beta state, but it does support basic GET/SET/DEFAULT/IF statements and I’m slowly adding more as I get more comfortable with ANTLR.

Posted in Software | Tagged , , , , , , | Comments Off

Writing ReSharper 4.5.x Macros

While working on the MVC Marathon, I decided to try out ReSharper and write some good templates to make my time unit testing in ASP.NET MVC a little quicker. I soon realized that I needed a macro that would turn the unit test class name (HomeControllerTests) into the name of the controller being tested (HomeController).

Continue reading

Posted in Articles | Tagged , | 3 Comments

Macbook Pro Go Boom

Slowly over the last couple of weeks, my Macbook Pro started going downhill. It started with a big bad pixel in the top middle of the screen. Nothing worth pursuing since there was only one. Then Saturday while doing some full screen editing in Textmate I noticed a rash of speckles on the right side. I thought it was dirt. Of course, it didn’t come off when I cleaned the screen. Continue reading

Posted in Apple | Tagged , , | Comments Off

Monitoring Local Directories with Siphon

This is the third in a series of posts about Siphon, a set of data monitoring utilities for .NET under the MIT license. The source code can be found on GitHub.

Continue reading

Posted in Articles | Tagged , , | Comments Off

Siphon Configuration

This is the second in a series of posts about Siphon, a set of data monitoring utilities for .NET under the MIT license. The source code can be found on GitHub.

Continue reading

Posted in Articles | Tagged , | Comments Off

An Introduction To Siphon

This is the first in a series of posts about Siphon, a set of data monitoring utilities for .NET under the MIT license. The source code can be found on GitHub.

Continue reading

Posted in Articles | Tagged , , , , , , | Comments Off