mason/dhandler (.contact): Nudge index-scanning loop to focus on top level.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 15 Jun 2023 16:28:05 +0000 (17:28 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 15 Jun 2023 16:30:23 +0000 (17:30 +0100)
If, say, we want to do something else with the direct contents of the
directory, then it would be nice if this were easy.  Pull the variable
declarations out, pull an initial priming call to `listdir' out, and
move the inner `listdir' to the end of the loop.

mason/dhandler

index de50cd8..94c39cc 100755 (executable)
@@ -89,8 +89,9 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
          { $tn{$f} = TrivGal::Image->new($path . $f->name)->scale($size); }
        for my $d (@$dd) {
          my $p = join_paths $path, $d->name;
+         my ($ddd, $fff, $iii);
+         ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
          DIR: for (;;) {
-           my ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
            if (defined $iii) {
              my $index = join_paths $p, $iii->name;
              $tn{$d} = TrivGal::Image->new($index)->scale($size);
@@ -98,6 +99,7 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
            }
            if (!@$ddd) { $tn{$d} = undef; last DIR; }
            $p = join_paths $p, $ddd->[0]->name;
+           ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
          }
        }
 </%perl>