use strict;
use base qw/Class::Accessor::Fast Class::Data::Inheritable/;
use NEXT;
+use Catalyst::Utils;
__PACKAGE__->mk_classdata($_) for qw/_config _plugins/;
# 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)
}
else {
my $class = ref $self || $self;
- my $new = { %{ $self->config }, %{$arguments} };
+ my $new = $self->merge_config_hashes( $self->config, $arguments );
return bless $new, $class;
}
}
$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;
}
. " 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)