Fix cleaned up config files code
[scpubgit/App-SCS.git] / lib / App / SCS / PageSet.pm
index f5b9e5e..d276840 100644 (file)
@@ -64,35 +64,19 @@ sub get {
 sub _config_files_for {
   my ($self, $path) = @_;
 
-  my @files = ();
-  my @dirs = io->dir($path)->splitdir;
+  my @dir_parts = io->dir($path)->splitdir;
+  my @dirs = map io->dir('')->catdir(@dir_parts[1..$_]), 1..($#dir_parts - 1);
 
-  shift @dirs;
-  pop @dirs;
-  my $build_path = io('');
-
-  foreach my $dir (@dirs) {
-    $build_path = $build_path->catdir("/$dir");
-    #/home/.../share/pages/blog.conf etc
-
-    my $file = $self->_top_dir->catfile("$build_path.conf");
-
-    if (!$file->exists || !$file->file || $file->empty) {
-        next;
-    }
-
-    push @files, $file;
-  }
-
-  return \@files;
+  return grep +($_->is_file and $_->exists and not $_->empty),
+           map $self->_top_dir->catfile("${_}.conf"), @dirs;
 }
 
 sub _inflate {
   my ($self, $type, $path, $io) = @_;
   (my $cache_name = $io->name) =~ s/\/([^\/]+)$/\/.htcache.$1.json/;
   my $cache = io($cache_name);
-  my $config_files = $self->_config_files_for($path);
-  my $max_stat = max map $_->mtime, $io, @$config_files;
+  my @config_files = $self->_config_files_for($path);
+  my $max_stat = max map $_->mtime, $io, @config_files;
 
   if (-f $cache_name) {
     if ($cache->mtime >= $max_stat) {
@@ -108,7 +92,7 @@ sub _inflate {
 
     my $extracted = $self->${\"_extract_from_${type}"}($raw);
     my $jsony = JSONY->new;
-    my $config = reduce { merge($a, $jsony->load($b->all)) } [], @$config_files;
+    my $config = reduce { merge($a, $jsony->load($b->all)) } [], @config_files;
 
     $extracted->{plugins} = pond_read_datum('[' . $extracted->{plugins} . ']');