rework $c->stats to cooperate with new subrequest plugin
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Component.pm
index 4b12fda..d4cf7e5 100644 (file)
@@ -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)