[Catalyst] setup() called twice

Matt Lawrence matt.lawrence at ymogen.net
Tue Jun 19 18:19:30 GMT 2007


Matt S Trout wrote:
> On Tue, Jun 19, 2007 at 04:52:08PM +0100, Matt Lawrence wrote:
>   =

>> Matt S Trout wrote:
>>     =

>>> On Tue, Jun 19, 2007 at 09:50:30AM +0100, Matt Lawrence wrote:
>>>       =

>>>> What's wrong with:
>>>>
>>>> $_->setup for keys %{$self->_plugins};
>>>>     =

>>>>         =

>>> Setup order matters.
>>>
>>>   =

>>>       =

>> Fine, the order is known in setup(), but gets discarded.
>>
>> $class->setup_plugins($flags->{plugins});
>>
>> ...
>>
>> # Call plugins' setup
>> $_->setup for @{delete $flags->{plugins} || []};
>>     =

>
> Still completely broken.
>
> Read half a dozen plugins' setup methods and come back when you have a cl=
ue.
>
>   =


Nothing like a bit of random abuse to spark off a bit of development work...

This patch implements what I was driving at. All tests pass with =

Catalyst::Runtime 5.7007.

I didn't include a test for the case of overridden setup, but it should =

be fixed. Feel free to flame me if it's not.

Matt


-------------- next part --------------
--- Catalyst-Runtime-5.7007/lib/Catalyst.pm	2007-02-28 15:20:30.000000000 +=
0000
+++ Catalyst-Runtime-5.7007-plugin-patch/lib/Catalyst.pm	2007-06-19 18:08:1=
2.000000000 +0100
@@ -807,8 +807,11 @@
 =

     $class->setup_home( delete $flags->{home} );
 =

+    # We will need this later on..
+    my $plugins =3D delete $flags->{plugins};
+
     $class->setup_log( delete $flags->{log} );
-    $class->setup_plugins( delete $flags->{plugins} );
+    $class->setup_plugins( $plugins );
     $class->setup_dispatcher( delete $flags->{dispatcher} );
     $class->setup_engine( delete $flags->{engine} );
 =

@@ -860,10 +863,11 @@
     }
 =

     # Call plugins setup
-    {
-        no warnings qw/redefine/;
-        local *setup =3D sub { };
-        $class->setup;
+    for my $plugin (@{ $plugins || [] }) {
+        if (defined(my $setup =3D $plugin->can('setup'))) {
+            $setup->($class);
+            last;
+        }
     }
 =

     # Initialize our data structure


More information about the Catalyst mailing list