more granular top-level hash merging
Brian Cassidy [Tue, 23 May 2006 11:40:43 +0000 (11:40 +0000)]
Changes
lib/Catalyst/Plugin/ConfigLoader.pm

diff --git a/Changes b/Changes
index 7d8737f..e2d78b7 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,8 @@ Revision history for Perl extension Catalyst::Plugin::ConfigLoader.
 0.08  Mon May 15 2006\r
     - added get_config_path() which extracts the path finding code\r
     - added the ability to specify a MYAPP_CONFIG ENV variable\r
+    - fixed debug typo\r
+    - more granular merging of top-level hashrefs\r
 \r
 0.07  Mon May 01 2006\r
     - added Config::General support\r
index 760c57e..edc69d4 100644 (file)
@@ -68,8 +68,24 @@ sub setup {
             my $config = $loader->load( $_ );\r
 \r
             $c->log->debug( "Loaded Config $_" ) if $c->debug;\r
-           _fix_syntax( $config );\r
-            $c->config( $config ) if $config;\r
+            \r
+            next if !$config;\r
+\r
+            _fix_syntax( $config );\r
+            \r
+            # merge hashes 1 level down\r
+            for my $key ( keys %$config ) {\r
+                if( exists $c->config->{ $key } ) {\r
+                    my $isa_ref = ref $config->{ $key };\r
+\r
+                    next if !$isa_ref or $isa_ref ne 'HASH';\r
+\r
+                    my %temp = ( %{ $c->config->{ $key } }, %{ $config->{ $key } } );\r
+                    $config->{ $key } = \%temp;\r
+                }\r
+            }\r
+            \r
+            $c->config( $config );\r
         }\r
     }\r
 \r