[Catalyst] Wierd config behavior solved (was Re: Creating my own controller....)

Matt S Trout dbix-class at trout.me.uk
Fri Apr 28 20:53:01 CEST 2006


John Napiorkowski wrote:
> I spent a lot of time digging into the trouble with
> using __PACKAGE__->config with subclassed controllers.
>  The short story is that the solution from Matt (using
> "__PACKAGE__->_config({ %{ __PACKAGE__->_config }
> });") did work, although it's not so pretty since you
> need to put it in front of EVERY controller that is
> subclassing.
 >
> Although this solution does the trick, I looked into
> this further, since I really think this solution is a
> bit undesirable.  Personally I prefer to encapsulate
> common behavior to base classes (as I am sure many of
> you do) and having that line stuck in the top of every
> controller is just going to cause me trouble sooner or
> later.  For example I am sure that myself or another
> programming will forget to do this, or not understand
> why it is there in the first place and remove it.

Yes. That's why I was guiding you towards a test case we can commit to 
Catalyst trunk and get this fixed in Catalyst::Component itself.

> The config method is inherited from
> Catalyst::Component.  It's actually not a lot of
> lines, so I'll just paste it here for our help:
> 
> sub config {
>     my $self = shift;
>     $self->_config( {} ) unless $self->_config;
>     if (@_) {
           my $orig_config = { %{$self->_config} };
>         my $config = @_ > 1 ? {@_} : $_[0];
>         while ( my ( $key, $val ) = each %$config ) {
>             $orig_config->{$key} = $val;
>         }
           $self->_config($orig_config);
>     }
>     return $self->_config;
> }

should be the fix.

> Anyway, at least I have a solution I can live with for
> now.  Hopefully my post will save someone else the
> trouble I had, and just maybe someone smarter than me
> at this (most of you I imagine :) ) will read this and
> have an 'ah ha' moment and grasp the trouble.

I already grasped the trouble. That's how I was able to give you a workaround :)

Can I have that test patch please?

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Catalyst mailing list