04bfb0
From a4e94e39cfa6852b1d57e61ee122c8083ab9d82e Mon Sep 17 00:00:00 2001
04bfb0
From: Hauke D <haukex@zero-g.net>
04bfb0
Date: Mon, 20 Nov 2017 15:31:57 +0100
04bfb0
Subject: [PATCH] Tie::StdHandle::BINMODE: handle layer argument
04bfb0
MIME-Version: 1.0
04bfb0
Content-Type: text/plain; charset=UTF-8
04bfb0
Content-Transfer-Encoding: 8bit
04bfb0
04bfb0
Fixes #16262
04bfb0
04bfb0
BINMODE was not handling the LAYER argument.
04bfb0
Also bump the version number.
04bfb0
04bfb0
(cherry picked from commit 479d04b98e5b747e5c9ead7368d3e132f524a2b7)
04bfb0
Signed-off-by: Nicolas R <atoomic@cpan.org>
04bfb0
Signed-off-by: Petr Písař <ppisar@redhat.com>
04bfb0
---
04bfb0
 lib/Tie/Handle/stdhandle.t | 13 ++++++++++++-
04bfb0
 lib/Tie/StdHandle.pm       |  4 ++--
04bfb0
 2 files changed, 14 insertions(+), 3 deletions(-)
04bfb0
04bfb0
diff --git a/lib/Tie/Handle/stdhandle.t b/lib/Tie/Handle/stdhandle.t
04bfb0
index d2f04bcc5c..6c20d90f2b 100644
04bfb0
--- a/lib/Tie/Handle/stdhandle.t
04bfb0
+++ b/lib/Tie/Handle/stdhandle.t
04bfb0
@@ -5,7 +5,7 @@ BEGIN {
04bfb0
     @INC = '../lib';
04bfb0
 }
04bfb0
 
04bfb0
-use Test::More tests => 27;
04bfb0
+use Test::More tests => 29;
04bfb0
 
04bfb0
 use_ok('Tie::StdHandle');
04bfb0
 
04bfb0
@@ -72,6 +72,17 @@ is($b, "rhubarbX\n", "b eq rhubarbX");
04bfb0
 $b = <$f>;
04bfb0
 is($b, "89\n", "b eq 89");
04bfb0
 
04bfb0
+# binmode should pass through layer argument
04bfb0
+
04bfb0
+binmode $f, ':raw';
04bfb0
+ok !grep( $_ eq 'utf8', PerlIO::get_layers(tied(*$f)) ),
04bfb0
+    'no utf8 in layers after binmode :raw';
04bfb0
+binmode $f, ':utf8';
04bfb0
+ok grep( $_ eq 'utf8', PerlIO::get_layers(tied(*$f)) ),
04bfb0
+    'utf8 is in layers after binmode :utf8';
04bfb0
+
04bfb0
+# finish up
04bfb0
+
04bfb0
 ok(eof($f), "eof");
04bfb0
 ok(close($f), "close");
04bfb0
 
04bfb0
diff --git a/lib/Tie/StdHandle.pm b/lib/Tie/StdHandle.pm
04bfb0
index dfb86634f0..fb79a986c6 100644
04bfb0
--- a/lib/Tie/StdHandle.pm
04bfb0
+++ b/lib/Tie/StdHandle.pm
04bfb0
@@ -4,7 +4,7 @@ use strict;
04bfb0
 
04bfb0
 use Tie::Handle;
04bfb0
 our @ISA = 'Tie::Handle';
04bfb0
-our $VERSION = '4.5';
04bfb0
+our $VERSION = '4.6';
04bfb0
 
04bfb0
 =head1 NAME
04bfb0
 
04bfb0
@@ -48,7 +48,7 @@ sub TELL    { tell($_[0]) }
04bfb0
 sub FILENO  { fileno($_[0]) }
04bfb0
 sub SEEK    { seek($_[0],$_[1],$_[2]) }
04bfb0
 sub CLOSE   { close($_[0]) }
04bfb0
-sub BINMODE { binmode($_[0]) }
04bfb0
+sub BINMODE { &CORE::binmode(shift, @_) }
04bfb0
 
04bfb0
 sub OPEN
04bfb0
 {
04bfb0
-- 
04bfb0
2.21.0
04bfb0