[Catalyst] setup() called twice
Matt S Trout
dbix-class at trout.me.uk
Tue Jun 19 19:02:42 GMT 2007
On Tue, Jun 19, 2007 at 03:42:04PM +0100, Matt S Trout wrote:
> On Mon, Jun 18, 2007 at 01:27:07PM -0700, Quinn Weaver wrote:
> > On Mon Jun 18 20:04:09 GMT 2007, Matt Trout wrote:
> > On Mon, Jun 18, 2007 at 11:50:06AM -0700, Quinn Weaver wrote:
> >
> > > Hi, all,
> > >
> > > During some debugging, I noticed that MyApp::setup is called twice.
> > > This looks like an intentional feature. My question is, why?
> > >
> > > From MyApp.pm:
> > >
> > > my $ret = $self->SUPER::setup( @_ );
> > >
> > > From Catalyst.pm:
> > >
> > > # Call plugins setup
> > > {
> > > no warnings qw/redefine/;
> > > local *setup = sub { };
> > > $class->setup;
> > > }
> > >
> > > Yep, the latter code locally redefines the parent class setup to a
> > > no-op in order to prevent an infinite loop, then calls the child class
> > > (MyApp) setup. The effect is that every line in MyApp::setup is
> > > executed twice.
> >
> > > No it isn't. The redefine means it -isn't- called a second time.
> >
> > Yes it is. You can verify this by running myapp_server.pl under the debugger,
> > or by putting lines like this in MyApp::setup:
> >
> > warn "setup called by process $$ at ", scalar localtime();
>
> Sorry, I read Catalyst::setup for MyApp::setup - I never have direct
> setup code in my app class, since I tend to handle everything I can
> via model/view/controller components rather than turning MyApp into a god
> object (not to say you are, but that's my motivation ...)
>
> I'd be fairly willing to say this is a bug and it should be doing
>
> {
> no strict 'refs';
> no warnings 'redefine';
> local *{"${appclass}::setup"} = sub { shift->NEXT::setup(@_); };
> local *setup = sub {};
> $app->setup;
> }
>
> Maybe somebody could put together a test case for this behaviour?
*PROD*
Quinn, that any better for you?
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director Want a managed development or deployment platform?
Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/
More information about the Catalyst
mailing list