This file documents the revision history for Perl extension Catalyst.
+ - added merge_config_hashes() as a convenience method
- Swapped out CGI::Cookie in favour of CGI::Simple::Cookie
- Removed test dependencies on Test::NoWarnings, Test::MockObject
- Removed dependency on UNIVERSAL::require
# 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_hash_config( $hashref, $hashref )
+
+Merges two hashes together recursively, giving right-hand precedence.
+
+=cut
+
+sub merge_config_hashes {
+ my ( $self, $lefthash, $righthash ) = @_;
+
+ my %merged = %$lefthash;
+ for my $key ( keys %$righthash ) {\r
+ my $right_ref = ( ref $righthash->{ $key } || '' ) eq 'HASH';\r
+ my $left_ref = ( ( exists $lefthash->{ $key } && ref $lefthash->{ $key } ) || '' ) eq 'HASH';\r
+ if( $right_ref and $left_ref ) {\r
+ $merged{ $key } = $self->merge_config_hashes(
+ $lefthash->{ $key }, $righthash->{ $key }
+ );\r
+ }
+ else {
+ $merged{ $key } = $righthash->{ $key };
+ }\r
+ }
+
+ return \%merged;
+}
+
=head1 OPTIONAL METHODS
=head2 ACCEPT_CONTEXT($c, @args)