X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FComponent.pm;h=d4cf7e59f768e96d70bc1a1619a1bc602c1c6da4;hb=e37e397712a443ae02f23cee03f6ba4ddda5bf64;hp=4b12fdab40932773a3a4addc2d8c79888862bec8;hpb=825dbf857c7bf90368937efaaeadec92d91fd990;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Component.pm b/lib/Catalyst/Component.pm index 4b12fda..d4cf7e5 100644 --- a/lib/Catalyst/Component.pm +++ b/lib/Catalyst/Component.pm @@ -3,6 +3,7 @@ package Catalyst::Component; use strict; use base qw/Class::Accessor::Fast Class::Data::Inheritable/; use NEXT; +use Catalyst::Utils; __PACKAGE__->mk_classdata($_) for qw/_config _plugins/; @@ -62,7 +63,7 @@ sub new { # Temporary fix, some components does not pass context to constructor my $arguments = ( ref( $_[-1] ) eq 'HASH' ) ? $_[-1] : {}; - return $self->NEXT::new( { %{ $self->config }, %{$arguments} } ); + return $self->NEXT::new( $self->merge_config_hashes( $self->config, $arguments ) ); } =head2 COMPONENT($c, $arguments) @@ -92,7 +93,7 @@ sub COMPONENT { } else { my $class = ref $self || $self; - my $new = { %{ $self->config }, %{$arguments} }; + my $new = $self->merge_config_hashes( $self->config, $arguments ); return bless $new, $class; } } @@ -116,8 +117,10 @@ sub config { $self->_config( $config = {} ); } if (@_) { - $config = { %{$config}, %{@_ > 1 ? {@_} : $_[0]} }; - $self->_config($config); + my $newconfig = { %{@_ > 1 ? {@_} : $_[0]} }; + $self->_config( + $self->merge_config_hashes( $config, $newconfig ) + ); } return $config; } @@ -132,6 +135,18 @@ sub process { . " did not override Catalyst::Component::process" ); } +=head2 $c->merge_config_hashes( $hashref, $hashref ) + +Merges two hashes together recursively, giving right-hand precedence. + +=cut + +sub merge_config_hashes { + my ( $self, $lefthash, $righthash ) = @_; + + return Catalyst::Utils::merge_hashes( $lefthash, $righthash ); +} + =head1 OPTIONAL METHODS =head2 ACCEPT_CONTEXT($c, @args)