clean up config merging
[scpubgit/App-SCS.git] / lib / App / SCS / PageSet.pm
index fb61a40..e44522c 100644 (file)
@@ -11,7 +11,6 @@ use List::Util qw(reduce max);
 use Module::Runtime qw(use_module);
 use JSON::MaybeXS;
 use Moo;
-use Hash::Merge qw(merge);
 use JSONY;
 
 with 'App::SCS::Role::PageChildren';
@@ -91,13 +90,16 @@ sub _inflate {
 
     my $extracted = $self->${\"_extract_from_${type}"}($raw);
     my $jsony = JSONY->new;
-    my $config = reduce { merge($a, $jsony->load($b->all)) } [], @config_files;
 
-    $extracted->{plugins} = $jsony->load($extracted->{plugins});
-
-    my $setup = $extracted;
-
-    $setup->{plugin_config} = merge($extracted->{plugins}, $config);
+    my $setup = {
+      %$extracted,
+      plugin_config => [
+        map @{$jsony->load($_)}, (
+          $extracted->{plugins},
+          (map $_->all, reverse @config_files), # apply config deepest first
+        )
+      ]
+    };
 
     try {
         my $tmp_cache = io($cache_name . ".tmp");