[Catalyst] When using multiple controllers as base

Tomohiro Teranishi tomohiro.teranishi at gmail.com
Sun Apr 1 10:11:36 GMT 2007


Hi,

http://tomyhero-perl-module.googlecode.com/svn/trunk/CatalystX-Controller-FormValidator-Lazy/

This is what I want to achieve , I just implement it on my way.

I wanted to know how to implement this in best practice way. Can you
look at it and give me a suggestion??

thanks,

Tomohiro


2007/4/1, Daisuke Maki <daisuke at endeworks.jp>:
>
> It's extremely hard to say whether or not you should do X or Y without
> knowing *exactly* what you are trying to achieve.
> I can only say that you *probably* shouldn't be using new(), but I
> really have no clue at this point.
>
> Perhaps you want to be using COMPONENT() or ACCEPT_CONTEXT()?
> COMPONENT() gets called once at setup() time, and ACCEPT_CONTEXT() gets
> called at various steps, when things like $c->controller() and
> $c->component() gets called.
>
> --d
>
>
> Tomohiro Teranishi wrote:
> > 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/
> >>
> >
> > _______________________________________________
> > 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