[Catalyst] Base controllers and multiple inheritance

Byron Young Byron.Young at riverbed.com
Thu Mar 6 18:31:04 GMT 2008


Peter Karman wrote:
> Byron Young wrote on 3/5/08 4:29 PM:
> 
>> 
>> Everything looks good, right?  My List actions work! However, the
>> CRUD actions don't work because the FormConfig actions seem to have
>> been ignored -- $c->stash->{form} is undef :(
> 
> I wouldn't expect anything in stash() to persist from request to
> request. Don't do anything with stash during new(). new() is called
> once per app life, at startup. stash() is for each request.
> 

Peter - thanks for taking the time to respond.

Sorry, I was unclear about that $c->stash->{form} comment.
$c->stash->{form} is created by the FormConfig action provided by
Catalyst::Controller::HTML::FormFu, which is a base class of my CRUD
base controller.  For some reason, even though it appears new() is being
called down both inheritance chains, the HTML::FormFu actions aren't set
up properly.

I want to be using new() in my base controllers mainly to set up and
error check config().  I understand it's only called once per app life -
I don't want to do config() error checking every request.

$class->NEXT::new() doesn't do the right thing with this crazy
diamond-ish inheritance I have, and I think using Class::C3 in my base
classes while Catalyst::Controller and C::C::HTML::FormFu use NEXT is
causing some problems.  I'll try to reproduce the behavior with a small
test later.  I guess it's not really Catalyst-specific, but I figured
Catalyst people would know since I saw some notes in the docs about
wanting to switch Catalyst over to c3.

My workaround for now is to have new() in each of my actual controller
classes which passes control up to Catalyst::Controller::new() and then
calls each superclass's __setup() method specifically.  I don't like
doing it this way, but for now I need to just keep moving ahead with
this project so I will leave it until a better solution appears.

>> 
>> Does anyone have any suggestions?  Should I just forego using new()
>> and do initial setup the first time auto() is called in each of my
>> base controllers?
> 
> depends on what kind of thing you are setting up. I have used multiple
> inheritance in my controllers to good effect (see
> CatalystX::CRUD::Controller
> and its descendents for example). In general, only set up things in
> new() (or its cousins) for stuff you want to set up once per app:
> config, persistent objects, etc. IME, there isn't much you want like
> that.

I think the difference between your CX::CRUD::Controller's multiple
inheritance and mine is that you don't have the diamond pattern.

As an aside -- I wish I had seen your CatalystX::CRUD::Controller
before!  I actually based mine off of your C::C::Rose::CRUD but wanted
to use DBIC and C::C::HTML::FormFu, so I made my own.  Anyway, kudos!

Thanks,
Byron



More information about the Catalyst mailing list