You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
perl-podlators/SOURCES/podlators-4.09-Coerce-file-...

46 lines
1.6 KiB

From 72b821db9a1e5e25febe2f3551dcb1ef273206c9 Mon Sep 17 00:00:00 2001
From: Russ Allbery <rra@cpan.org>
Date: Sun, 17 Sep 2017 11:38:23 -0700
Subject: [PATCH] Coerce file handle to glob for PerlIO::get_layers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[Pod::Man] Wrap the output file descriptor in a glob before passing it
to PerlIO::get_layers so that the layer check works properly.
Previously, this code would throw a warning if given a scalar not
wrapped in a glob and not detect layers properly. Patch from Zefram.
(#122521)
Petr Písař: Port to 4.09.
---
lib/Pod/Man.pm | 7 +++++--
diff --git a/lib/Pod/Man.pm b/lib/Pod/Man.pm
index db49bde..a737e5b 100644
--- a/lib/Pod/Man.pm
+++ b/lib/Pod/Man.pm
@@ -800,13 +800,16 @@ sub start_document {
# has a PerlIO encoding layer set. If it does not, we'll need to encode
# our output before printing it (handled in the output() sub). Wrap the
# check in an eval to handle versions of Perl without PerlIO.
+ #
+ # PerlIO::get_layers still requires its argument be a glob, so coerce the
+ # file handle to a glob.
$$self{ENCODE} = 0;
if ($$self{utf8}) {
$$self{ENCODE} = 1;
eval {
my @options = (output => 1, details => 1);
- my $flag = (PerlIO::get_layers ($$self{output_fh}, @options))[-1];
- if ($flag & PerlIO::F_UTF8 ()) {
+ my @layers = PerlIO::get_layers (*{$$self{output_fh}}, @options);
+ if ($layers[-1] & PerlIO::F_UTF8 ()) {
$$self{ENCODE} = 0;
}
}
--
2.13.6