Model adaptors for Catalyst.

2009-08-07 − 🏷 catalyst 🏷 model dbix::class 🏷 mvc 🏷 perl

In a recent post Dave Rolsky points out some of his own best practices for Catalyst. While I've come around to agree with his first point, that Catalyst should generate a reusable config class for the user, I'm not so sure with regards to his model viewpoints.

For me, the strength of Catalyst's Model layer has always been the immense glue layer that allows me to configure any model in a predictable way. Much like DBI gives me a unified way to talk to databases, the Catalyst model-layer gives us a unified way of configuring models. In addition, we are able to provide helpers to create these models from the command line, reducing the work needed to set up a new model.

I will grant Dave that the API for the model adapters could be better. It is my hope that we will accomplish as Catalyst takes advantage of more of the new stack that Moose provides. In particular I am excited about the work Devin Austin is doing for GSOC on improving the -Devel package. This is an area where we can significantly improve without too much worry about backwards compatibility. For instance, the KiokuDB model already uses moose accessors for config.

Dave's example only limits itself to talking to a SQL store via DBIx::Class. However, real world applications typically have several models. In some of my apps I talk to S3, or Queue servers, or LDAP stores for user management. This shows the true power of the Catalyst model layer.

I also hope that we can provide a different way to tie models to controllers. This should be part of the Moose-ify branch of Catalyst-Runtime. I disagree that $schema->resultset('Person') is a significant improvement on $c->model('DBIC::Person'). Controller code is not meant to run without a context anyways.

I hope that by looking at Moose Extensions, we will be able to find a more suitable API for this functionality. Of course, we have a lot of work ahead of us, but I am really starting to like what Catalyst has turned into.