[Catalyst] Unit Testing

Dave Rolsky autarch at urth.org
Sun Apr 20 05:08:49 BST 2008


On Sat, 19 Apr 2008, John Romkey wrote:

> I suspect that most Catalyst users build their applications so that the 
> controllers do too much work. I certainly did, and I'm gradually rewriting 
> mine to move most of the work into the model. Where before my controllers

A good way to approach a webapp is to think of the Controller as a thin 
shim between the the web/HTTP environment and your model.

The controller code should handle web/HTTP-specific things like URIs, form 
submissions, etc. and translate that into API calls on model classes. It 
also might handle something like authentication, since the way you 
authenticate a user via the web is different than how you'd do it via the 
command line.

Besides the testability benefits, another benefit is that it makes it easy 
to reuse this business logic in things like cron jobs, daemons, and 
command line driven code. Invariably, any app of a certain size will need 
this flexibility.

Of course, the ultimate benefit is that it's the only sane way to write an 
application ;)


-dave

/*==========================
VegGuide.Org
Your guide to all that's veg
==========================*/



More information about the Catalyst mailing list