[Catalyst] CDBI integration

Matt S Trout dbix-class at trout.me.uk
Tue Jun 13 14:09:14 CEST 2006


Len Jaffe wrote:
> 
>> Pablo Collins <pablo.collins at gmail.com> wrote:
>> I have a bunch of Class::DBI packages in a
>> directory/namespace outside of
>> the catalyst app I'm building and I would like to
>> make them available as the
>> model layer.
> 
> The short, and unhelpful answer is that nearly
> everybody around here, including myself, has drunk the
> DBIx::Class Kool-aid, and have stopped using
> Class::DBI   with Catalyst.
> 
>> It looks like if you want a model layer in catalyst,
>> each class has to be
>> inside the top-level namespace of the application. I
>> would prefer to not
>> have to create a package for each catalyst model
>> class that says "package
>> MyApp::Model::Foo; use base 'MyModel::Foo';" for
>> each package. It would be
>> neat if you tell the config where your model files
>> live and have catalyst
>> slurp them up.
> 
> Sounds like an excellent idea.

Easy enough to do if you namespace the models. Just have a Model::DB class 
that does a Module::Pluggable search for MyModel::* and creates the classes on 
the fly by pushing stuff into their @ISA. Catalyst will pick this up fine - 
it's how Catalyst::Model::DBIC::Schema imports all the result classes (equiv. 
to CDBI table classes) into the Model namespace (well, it uses DBIC's 
compose_namespace function but the basic process is @ISA stuffing plus a 
little extra magic to make all the DBIC bits work together).

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Catalyst mailing list