diff options
author | Russ Allbery <rra@cpan.org> | 2021-09-08 21:27:39 -0700 |
---|---|---|
committer | Russ Allbery <rra@cpan.org> | 2021-09-08 21:31:19 -0700 |
commit | 215b8b9bf6f088c76a70921b47c6349a39e5cf53 (patch) | |
tree | 3b67d7f144981bc155cefe5d5577501d2726a517 | |
parent | cda2e4a52a464dc6360047cd3683e5d4ab21ba0a (diff) |
Close file handles opened by \include
Clean up after ourselves. Also get rid of FileHandle in favor
of using a normal open.
-rw-r--r-- | lib/App/DocKnot/Spin.pm | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/App/DocKnot/Spin.pm b/lib/App/DocKnot/Spin.pm index 62b5d3f..d94778b 100644 --- a/lib/App/DocKnot/Spin.pm +++ b/lib/App/DocKnot/Spin.pm @@ -22,7 +22,6 @@ use App::DocKnot::Spin::Sitemap; use App::DocKnot::Spin::Versions; use Carp qw(croak); use Cwd qw(getcwd realpath); -use FileHandle (); use Getopt::Long qw(GetOptions); use Git::Repository (); use Image::Size qw(html_imgsize); @@ -971,9 +970,8 @@ sub _cmd_image { sub _cmd_include { my ($self, $file) = @_; $file = $self->_parse($file); - my $fh = FileHandle->new ("< $file") - or $self->_fatal("cannot include $file: $!"); - unshift($self->{files}->@*, [$fh, $file]); + open(my $fh, '<', $file); + push($self->{files}->@*, [$fh, $file]); return (1, ''); } @@ -1206,7 +1204,7 @@ sub _spin { # each time through the loop. local $/ = q{}; while ($self->{files}->@*) { - ($in_fh, $self->{file}) = $self->{files}[0]->@*; + ($in_fh, $self->{file}) = $self->{files}[-1]->@*; while (defined(my $para = <$in_fh>)) { if ("\n" !~ m{ \015 }xms && $para =~ m{ \015 }xms) { $self->_warning( @@ -1225,9 +1223,15 @@ sub _spin { if ($result !~ m{ \A \s* \z }xms) { $self->_output($result); } - ($in_fh, $self->{file}) = $self->{files}[0]->@*; + ($in_fh, $self->{file}) = $self->{files}[-1]->@*; + } + pop($self->{files}->@*); + + # Close the input file handle if it was one we opened, which is all of + # them except the last one in the stack. + if ($self->{files}->@*) { + close($in_fh); } - shift($self->{files}->@*); } # Close open tags and print any deferred whitespace. |