+ if ($writer) {
+ $writer->(\*OUT, $cleanup);
+ }
+ else {
+ print OUT $content or error("failed writing to $newfile: $!", $cleanup);
+ }
+ close OUT || error("failed saving $newfile: $!", $cleanup);
+ rename($newfile, "$destdir/$file") ||
+ error("failed renaming $newfile to $destdir/$file: $!", $cleanup);
+} #}}}
+
+my %cleared;
+sub will_render ($$;$) { #{{{
+ my $page=shift;
+ my $dest=shift;
+ my $clear=shift;
+
+ # Important security check.
+ if (-e "$config{destdir}/$dest" && ! $config{rebuild} &&
+ ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}})) {
+ error("$config{destdir}/$dest independently created, not overwriting with version from $page");
+ }
+
+ if (! $clear || $cleared{$page}) {
+ $renderedfiles{$page}=[$dest, grep { $_ ne $dest } @{$renderedfiles{$page}}];
+ }
+ else {
+ foreach my $old (@{$renderedfiles{$page}}) {
+ delete $destsources{$old};
+ }
+ $renderedfiles{$page}=[$dest];
+ $cleared{$page}=1;
+ }
+ $destsources{$dest}=$page;