[Catalyst] Catalyst Engine Start-up Flag?

Brian Cassidy brian.cassidy at nald.ca
Fri Apr 27 15:07:01 GMT 2007


Lee Goddard wrote:

> Sorry: I meant when the server starts, it seems to attempt to call 'new'
> for every *.pm in MyApp::Model::* :

Hopefully I recall how this works...

Every Model::*, Controller::*, View::* (plus their short-names for 
back-compat) are instantiated via setup_components (see Catalyst.pm).

Assuming the model inherits from Catalyst::Model, then the COMPONENT() 
sub is called. It in turn will either call in the parent COMPONENT() 
method or failing that, new() -- passing the context + config options.

So, if you have a normal module that is used outside of Catalyst as your 
base class, then you have to work around that.

package MyApp::Model::NormalThing;

use base qw( NormalThing );

sub COMPONENT {
	my( $class, $c, $config ) = @_;

	# return an instance of something
}

Sometimes that instance can be of the parent class, such as the case 
with my Gedcom model [1]:

     return $class->new( %$config );

Othertimes you'd write a wrapper class does some re-dispatching.

-Brian

(Please, someone correct me if I'm in any way off on this.)

[1] 
http://search.cpan.org/src/BRICAS/Catalyst-Model-Gedcom-0.03/lib/Catalyst/Model/Gedcom.pm



More information about the Catalyst mailing list