[Catalyst] Pulling My Hair Out with DBIx::Schema For Authentication and Authorization

hkclark at gmail.com hkclark at gmail.com
Wed Mar 29 04:54:53 CEST 2006

On 3/21/06, hkclark at gmail.com <hkclark at gmail.com> wrote:
> Based on Matt's suggestion to my email yesterday
> (http://www.gossamer-threads.com/lists/catalyst/users/5951), I have
> been hard at work trying to convert from "Simple" DBIx::Class to the
> "Schema" (DBIx::Class::Schema) approach.  I must be missing something
> because I can't get it to work.  I have searched through the archives
> and found other people talking about aspects of the problem I'm trying
> to solve, but I haven't found a close or complete enough example to
> put all the pieces together.  If I can get this working, I would be
> glad to post all of the code to the wiki as a self-contained example
> for the benefit of others.

Hi Everyone,

After beating my head against the wall for the past week, I finally
figured out the deal with this.  Turns out when
Catalyst::Plugin::Authentication::Store tries to pull up the Model for
my User class using:
  my $model = $c->model($user_class) || $c->comp($user_class);
It descends into _comp_search() of Catalyst.pm where a regex is used
to locate the component.  Because I had both a User and a UserRole
class, it found a match with UserRole when I really needed User.  That
caused things to blow sky high.  (As an interesting aside, while
$c->model($user_class) didn't work, the $c->comp($user_class) was

Ways to get around this problem (other than hacking the code of
Authentication::Store::DBIC to put the $c->comp() first):
1) Don't user "overlapping" names for your Model/Component classes
(IOW, one class name shouldn't be a subset of another name).
2) In your config (myapp.yml in my case), define "user_class" and
"role_class" as "DBIC::User" and "DBIC::Role" respectively (vs.
"MyApp::Model::DBIC::User" and "MyApp::Model::DBIC::Role").
3) It sounds like a new approach to _comp_search() (or related code)
has been applied to trunk in the Catalyst repository.  So, you could
wait for the next version of Cat or run from the development build.

Thanks to Matt for:
a) suggestions #2 and #3 above
b) conversing with me re this on IRC
c) the cool "'perldoc -l' and local copies of libraries trick" for
debugging things like this:
  mkdir -p lib/Catalyst/Plugin/Authentication/Store/DBIC
  cp `perldoc -l Catalyst::Plugin::Authentication::Store::DBIC` \
  cp `perldoc -l Catalyst::Plugin::Authentication::Store::DBIC::User` \
  cp `perldoc -l Catalyst::Plugin::Authentication::Store::DBIC::Backend` \

As promised, I offered to put this together as a step-by-step example
of both authentication and authorization using DBIC.  Assuming it
doesn't suck when it's done, it sounds like it might show up in the
examples dir of the Catalyst subversion repository (hopefully by the
end of the week).


More information about the Catalyst mailing list