[Catalyst] When using multiple controllers as base

Tomohiro Teranishi tomohiro.teranishi at gmail.com
Sun Apr 1 02:59:53 GMT 2007


Hi , Daisuke-san,

Thank you for your reply,

I believe I knew the future of NEXT.pm.

What I do want to do is making Controller Extension modules,  so I
wanted know if I can use new() or should not . And I thought there may
be a way to around use multiple extensions somehow even using new() ,
so I asked this question.

http://www.gossamer-threads.com/lists/catalyst/users/13163

For more specific , I created a plugin mention on the mailing list and
I am trying to convert it to controller extension. If I use new() in
the controller module , then if somebody want to use the controller
and C::C::FormBuilder both then can not avoid error unless modify
source code.  That is what I was worry about it.

So I guess I should not use new() in the controller??  Make sense??

thanks,

Tomohiro


2007/4/1, Daisuke Maki <daisuke at endeworks.jp>:
> 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/
> >
>
>
> _______________________________________________
> 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