[Catalyst] Model--best practice help

Dr. Jennifer Nussbaum bg271828 at yahoo.com
Mon Oct 6 10:46:27 BST 2008


> 
> Without seeing a tremendous amount of your code it is hard
> to answer,
> but it sounds like you are either at a point where it would
> be
> advantageous to learn Moose, or start doing some multiple
> inheritance
> hacks to get things working.
> 
> The simple approach, which is much less "great"
> than using Moose, is
> to put your App specific (the Catalyst specific, as you
> phrased it)
> methods in a class, and then in your model class:
> 
> package MyApp::Model::Everything;
> 
> use base qw/Catalyst::Model::DBIC::Schema
> MyApp::Model::Book/;
> 
> __PACKAGE__->config( ... );
> 
> 1;
> 
> Then you can do
> $c->model('Everything')->foo_method( ... );
> (foo_method defined in Model::Book), and still have
> $c->model('Everything::SchemaClass')->search(...);
> 
> In foo_method, $self will be Catalyst::Model::DBIC::Schema,
> so you can
> do
> $self->schema->resultset('SchemaClass')->search(...);
> etc.
> 
> But really... I'd just learn Moose, it'll make
> things easier and
> cleaner in the long run.

The thing you suggested is already where i am now, though: i have $c->model('Book')->foo_method for my "Cat specific" stuff, and
$c->model('MyApp::Book')->find($id) for my Schema stuff.

I know that Moose is the way to go for the future, esp. for Catalyst's future, but is there something I can do for now if im not ready to
commit to it just yet? What have people been doing up to now--there's no way to multiple-inherit so that i only have one model class to call?

Jen


      



More information about the Catalyst mailing list