summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Allbery <rra@cpan.org>2022-01-16 20:55:32 -0800
committerRuss Allbery <rra@cpan.org>2022-01-16 20:55:32 -0800
commit6505e90ea753952f08d8c116e8a328b45096e120 (patch)
treeeae19d8bd9bcf7728f320271f6341cc1b3dfd5be
parentceed1ea14819282482129ad02482cdeb5b4432f4 (diff)
Process .rss files first in a separate pass
When spinning an input tree, process all .rss files first in a separate pass. This ensurse the output files are seen when spinning the tree into the output directory.
-rw-r--r--Changes4
-rw-r--r--lib/App/DocKnot/Spin.pm26
-rwxr-xr-xt/spin/tree.t10
3 files changed, 19 insertions, 21 deletions
diff --git a/Changes b/Changes
index a5bbcdf..5a87d64 100644
--- a/Changes
+++ b/Changes
@@ -14,6 +14,10 @@
- Fix .versions updating via docknot release when the package that needs
to be udpated is not the first line of the file.
+ - When spinning an input tree, process all .rss files first in a separate
+ pass. This ensurse the output files are seen when spinning the tree
+ into the output directory.
+
6.01 - 2022-01-15
- Add new docknot release command and corresponding App::DocKnot::Release
diff --git a/lib/App/DocKnot/Spin.pm b/lib/App/DocKnot/Spin.pm
index 7e76f33..fbb1656 100644
--- a/lib/App/DocKnot/Spin.pm
+++ b/lib/App/DocKnot/Spin.pm
@@ -360,8 +360,6 @@ sub _report_action {
#
# Throws: Text exception on any processing error
# autodie exception if files could not be accessed or written
-#
-## no critic (Subroutines::ProhibitExcessComplexity)
sub _process_file {
my ($self, $input) = @_;
@@ -387,10 +385,6 @@ sub _process_file {
$self->_report_action('Creating', $output);
$output->mkpath();
}
- my $rss_path = path($input, '.rss');
- if ($rss_path->exists()) {
- $self->{rss}->generate("$rss_path", "$input");
- }
} elsif ($input->basename() =~ m{ [.] spin \z }xms) {
my $output = $self->_output_for_file($input, '.spin');
$self->{generated}{"$output"} = 1;
@@ -512,7 +506,6 @@ sub spin {
# Reset data from a previous run.
delete $self->{repository};
- delete $self->{rss};
delete $self->{sitemap};
delete $self->{versions};
@@ -546,13 +539,14 @@ sub spin {
$self->{repository} = Git::Repository->new(work_tree => $input);
}
- # Create a new RSS generator object.
- $self->{rss} = App::DocKnot::Spin::RSS->new({ base => $input });
-
- # Process an .rss file at the top of the tree, if present.
- my $rss_path = $input->child('.rss');
- if ($rss_path->exists()) {
- $self->{rss}->generate("$rss_path", "$input");
+ # Process all .rss files in the input tree first. This is done as a
+ # separate pass because Path::Iterator::Rule appears to not always re-read
+ # the directory when it's modified during the iteration.
+ my $rss = App::DocKnot::Spin::RSS->new({ base => $input });
+ my $rule = Path::Iterator::Rule->new()->name('.rss');
+ my $iter = $rule->iter("$input", { follow_symlinks => 0 });
+ while (defined(my $file = $iter->())) {
+ $rss->generate(path($file), path($file)->parent);
}
# Create a new thread converter object.
@@ -581,9 +575,9 @@ sub spin {
#>>>
# Process the input tree.
- my $rule = Path::Iterator::Rule->new();
+ $rule = Path::Iterator::Rule->new();
$rule = $rule->skip($rule->new()->name($self->{excludes}->@*));
- my $iter = $rule->iter("$input", { follow_symlinks => 0 });
+ $iter = $rule->iter("$input", { follow_symlinks => 0 });
while (defined(my $file = $iter->())) {
$self->_process_file(path($file));
}
diff --git a/t/spin/tree.t b/t/spin/tree.t
index 700f961..2376bda 100755
--- a/t/spin/tree.t
+++ b/t/spin/tree.t
@@ -2,7 +2,7 @@
#
# Test running spin on a tree of files.
#
-# Copyright 2021 Russ Allbery <rra@cpan.org>
+# Copyright 2021-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT
@@ -32,14 +32,14 @@ setlocale(LC_ALL, 'C');
my $EXPECTED_OUTPUT = <<'OUTPUT';
Generating thread file .../changes.th
Generating RSS file .../changes.rss
-Updating .../changes.rss
-Spinning .../changes.html
-Spinning .../index.html
-Creating .../journal
Generating index file .../journal/index.th
Generating RSS file .../journal/index.rss
Generating RSS file .../journal/debian.rss
Generating RSS file .../journal/reviews.rss
+Updating .../changes.rss
+Spinning .../changes.html
+Spinning .../index.html
+Creating .../journal
Updating .../names.png
Spinning .../random.html
Creating .../reviews