[Catalyst] Base controllers and multiple inheritance

Byron Young Byron.Young at riverbed.com
Wed Mar 5 07:36:10 GMT 2008


Hi,

I've been using Catalyst for a project and decided to make some base
controllers for common functionality.  So far I've made two: CRUD, and
List, for standard database operations and for sortable, paged listings
of data.  They work fine on their own but I'm running into trouble with
multiple inheritance.  If I have a controller for some database table
that I want to inherit the actions from both CRUD and List, only the
first one inherited will initialize properly.

The inheritance looks like this:

                   Catalyst::Controller
                        /        \
                       /          \
                      /            \
                     /            Catalyst::Controller::HTML::FormFu
                    /               |
MyApp::Base::Controller::List       |
                    \               |
                     \            MyApp::Base::Controller::CRUD
                      \            /
                       \          /
                        \        /
               MyApp::Controller::SomeDatabaseTable


Each of the controller base classes has a new() method which sets up
config data and does error checking and whatnot.  If I inherit both of
my base classes, only new() on the first inherited is called.  I've
tried calling $class->NEXT::new(@_) in each, and I've also tried
Class::C3's $class->maybe::next::method(@_), but new() is still not
called down the second inheritance chain.  When I tried the Class::C3
approach I called Class::C3::initialize() in MyApp.pm - I wasn't sure
where to call it so I tried before and after MyApp->setup() - still no
luck.

Can somebody tell me why new() isn't called down both paths?

Thanks,
Byron



More information about the Catalyst mailing list