[Catalyst] what's the point of Catalyst::Model::CDBI::Plain?

Jonathan Manning jmanning at alisa-jon.net
Fri Aug 5 19:36:38 CEST 2005


Marcus Ramberg wrote:
> Using the ::Plain base class means that all your model classes will be
> loaded automatically at  startup of your application. Catalyst
> initializes all Classes that inherit from Catalyst::Base in the
> MyApp::[[M|V|C]] namespaces. That's all,  I guess.

Hm. I thought simply putting a class in the model directory and package
would get your model classes loaded automatically (without inheriting
from anything Catalyst). The debug log seems to reflect this for my
Catalyst-free model classes.

Module::Pluggable::Fast will do a 'require' on each of the classes in
the namespace. This loading has no dependancy on inheriting from
Catalyst::Base. (Well, see the part about calling new below, but that
doesn't change that your class is loaded via require.)

What does Catalyst::Base do then? I was curious about this too, so I did
some investigating. Inheriting from Catalyst::Base gives you access to:
 * Catalyst::Setup/Module::Pluggable::Fast will call $class->new($c,
$config) on load. It does nothing by default, but gives you a hook for
initialization time stuff.
 * $self->log
 * $self->config
 * Other catalyst methods that are not related/useful to a Model class.

As is clear from my previous thread, I've found CDBI::Plain just causes
problems. Several other replies indicate others are also just skipping
Catalyst for the Model classes.

It almost makes sense - the model isn't tied to Catalyst. A model
doesn't require any request information and it isn't outputting any
content directly - a model simply retrieves and updates the requested
data at the controller's request. By design, it's completely isolated
from the interface.

But I digress. I just wanted to challenge the above statement that you
must inherit from Catalyst::Base to be loaded automatically...

~Jonathan






More information about the Catalyst mailing list