[Catalyst-dev] Problems with $c->model() and _comp_singular()

Nathan Kurz nate at verse.com
Tue Aug 8 08:29:55 CEST 2006


I was just changing some things with my DBIx::Class schema's, and ran
into some problems that stumped me for a bit.  I had been calling
$c->model() and having it choose the correct model, but after I
rearranged the items in MyApp::Model::* things stopped working.  

I put in a debug statement like this:
  sub test : Local {
      my ($self, $c) = @_;
      $c->log->dumper('ref $c->model: ' . ref $c->model);
  }
And to my surprise found that $c->model made no sense at all:
  [debug] $VAR1 = 'ref $c->model: DBIx::Class::ResultSet';

Looking at Catalyst.pm, it appears that the problem is that
_comp_singular() is broken.  Currently, it looks like this:

  sub _comp_singular {
      my ( $c, @prefixes ) = @_;
      my $appclass = ref $c || $c;
      my ( $comp, $rest ) =
        map { $c->_comp_search("^${appclass}::${_}::") } @prefixes;
      return $comp unless $rest;
  }

I'm not certain, but since @prefixes comes in as ('Model', 'M'), and
since _comp_search() returns the first matching item, I think what
this does is to return the (unordered) first matching item if there is
also a class that matches prefix 'M', and then by chance to return
the same thing otherwise due to the lack of an explicit return value.

I've solved my problems by setting an explicit 'default_model' in my
config file, but I think it would be good to have someone with more
familiarity with the internals look at this and verify that it is
doing the right thing.  I could take my stab at a patch, but I'm not
even sure what the desired behaviour would be.

Thanks!

Nathan Kurz
nate at verse.com






More information about the Catalyst-dev mailing list