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