[Catalyst] Models Inheriting from Catalyst::Base

Jules Bean jules at jellybean.co.uk
Fri Nov 18 08:58:49 CET 2005


Brandon Black wrote:

I answered this on the wiki a couple of weeks ago I'll answer it again here:

> $c->comp('App::M::CDBI::MyTable')->a_table_method();
> 
> as opposed to otherwise just using:
> 
> App::M::CDBI::MyTable->a_table_method();
> 
> directly.  I don't yet understand the advantage of using $c->comp() at
> all, either.

$c->comp('App::M::CDBI::MyTable') is an object. An instance, if that's 
the terminology you prefer.

App::M::CDBI::MyTable is a class.

That's an important difference.

If your model inherits from Catalyst::Base then catalyst will 
automatically create a distinguished instance of it at setup time. That 
instance is then available from $c->comp('App::M::CDBI::MyTable') and, 
slightly less verbosely if I have correct understood the 5.5 release 
notes, $c->mode('CDBI::MyTable').

It so happens that CDBI and the current version of DBIC both happen to 
use a class-based syntax for the key methods search/retrieve/find. 
Because of that the different between a class and an instance happens to 
be moot (for this particular model). I am reliably informed that other 
models do not suffer this confusion, and so for users of other modules 
it is a bit more obvious what the 'point' of Catalyst::Base (or 
Catalyst::Model) is.

Jules

PS in grand usenet tradition I hope that by posting this message, if 
nothing else, I will provoke one of the powers-that-be into correcting me!



More information about the Catalyst mailing list