[Catalyst] When using multiple controllers as base

Daisuke Maki daisuke at endeworks.jp
Sat Mar 31 18:24:07 GMT 2007


That's a "feature" in NEXT.pm.

If your class hierarchy including the base class (the *real* base class, 
in this case Class::Accessor) don't properly use NEXT.pm, then you don't 
get the benefit of re-dispatch for multiple paths.

So you do need to be careful when you want multiple inheritance in your 
controllers... However, in your particular case you should be able to 
get away by just putting FormBuilder before BindLex as BindLex doesn't 
require any special initialization in new().

Of course, if you *really* wanted to, you could modify the behavior of 
NEXT.pm for the duration of your application...

   sub NEXT::ELSEWHERE::ancestors {
       my @inlist = shift;
       my @outlist = @inlist;
       my @parents = @inlist;

       while (my $parent = shift @parents) {
           no strict 'refs';
           my @isa = @{"${parent}::ISA"};
           if (@isa) {
               push @outlist, @isa;
               push @parents, @isa;
           }
       }
       return @outlist;
   }

This will force NEXT.pm to look at immediate parents first, but will 
change NEXT.pm semantics, so if anything really relies on its awkward 
behavior (to me anyway) this change may break things.

Use at your own risk ;)

--d

Tomohiro Teranishi wrote:
> Hi,
> 
> I was looking at source code for C::C::FormBuilder to know how to
> write Controller extention module. Then I thought using new() method
> is nice idea to run only once.
> 
> But I realize when I want to use two controller extention modules same
> time, it may cause problem because of NEXT specification.
> 
> e.x.
> 
> Let's say , I want to use C::C::FormBuilder and C::C::BindLex same time.
> 
> # Below case is OK
> use base qw/Catalyst::Controller::FormBuilder 
> Catalyst::Controller::BindLex/;
> 
> # In this case,  C::C::FormBuilder->new will not called.
> use base qw/Catalyst::Controller::BindLex 
> Catalyst::Controller::FormBuilder/;
> 
> I think only first base module run NEXT but not the others.
> 
> Am I doing something wrong??
> or should not use new() ??
> or should not use multiple controllers??
> 
> thanks,
> 
> Tomohiro Teranishi
> 
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
> 




More information about the Catalyst mailing list