[Catalyst-dev] Design Question brought about via work on C::P::A::S::DBIC

Alex Kavanagh alex at tinwood.homelinux.org
Thu Feb 23 13:32:05 CET 2006


Hi

I've run into a fundamental design problem regarding some mods I was
making to Catalyst::Plugin::Authentication::Storage::DBIC.

I've been modifying the code to support Catalyst::Model::DBIC::Schema
and after a bit of chat, concluded that using ->model was the best way
of getting the DBIx::Class object for the User table.

The problem can be stated:

What do I call ->model('Model::Table') on?

At the current stage I'm caching the $c when Backend.pm is created so
that User.pm has a instance on which ->model can be called.

However, this means that this instance of $c will be held for the
lifetime of the application and will be *different* to the $c that
request might be using to access the authentication modules.

An alternative, after discussing on #catalyst, was to cache the class
name of the application in Backend.pm so that ->model can be called on
that instead:

$class->model('Model::Table')

rather than

$first_instance->model('Model::Table')

So which is better, or is there an alternative way of doing this.

The *reason* I wanted to use ->model is that it works great for both
DBIx::Class and DBIx::Class::Schema models and makes the configuration
very simple: just set 'user_class' to 'SomeModel::SomeTable' and
->model( $user_class ) will either resolve to a DBIx::Class instance
or return a null.  If it's a null assume that 'user_class' is in the
form of 'AppName::SomeModel::SomeTable' and therefore it's Class::DBI
instead.

Any ideas?

Thanks
Alex (a.k.a tinwood on IRC).



More information about the Catalyst-dev mailing list