[Catalyst] setup() called twice

Quinn Weaver quinn at fairpath.com
Mon Jun 18 21:27:07 GMT 2007


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();

> But all the plugins' setup() methods (which weren't in @ISA when setup was
> first called) -are- called.

Thanks--I see the motivation now.  But it seems to have the unintended side
effect of calling MyApp::setup twice.

-- 
Quinn Weaver, independent contractor  |  President, San Francisco Perl Mongers
http://fairpath.com/quinn/resume/     |  http://sf.pm.org/
510-520-5217



More information about the Catalyst mailing list