From fd0cd1b62cf35ecfaa9e47c54c5a0960ccb08306 Mon Sep 17 00:00:00 2001 From: Leon Timmermans Date: Wed, 20 Jan 2021 00:37:54 +0100 Subject: [PATCH] Make use open :std push layers without any munging Previously it would only apply the first layer that was either :utf8 or any other layer with and argument (e.g. :encoding(utf8)). --- lib/open.pm | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/open.pm b/lib/open.pm index 3e213816f92b..86111ca8640d 100644 --- a/lib/open.pm +++ b/lib/open.pm @@ -1,7 +1,7 @@ package open; use warnings; -our $VERSION = '1.12'; +our $VERSION = '1.13'; require 5.008001; # for PerlIO::get_layers() @@ -120,20 +120,11 @@ sub import { ${^OPEN} = join("\0", $in, $out); if ($std) { if ($in) { - if ($in =~ /:utf8\b/) { - binmode(STDIN, ":utf8"); - } elsif ($in =~ /(\w+\(.+\))/) { - binmode(STDIN, ":$1"); - } + binmode STDIN, $in; } if ($out) { - if ($out =~ /:utf8\b/) { - binmode(STDOUT, ":utf8"); - binmode(STDERR, ":utf8"); - } elsif ($out =~ /(\w+\(.+\))/) { - binmode(STDOUT, ":$1"); - binmode(STDERR, ":$1"); - } + binmode(STDOUT, $out); + binmode(STDERR, $out); } } } @@ -243,6 +234,10 @@ to this pragma in its own lexical scope. { use open ':std', IO => ':encoding(UTF-8)' } +Before Perl 5.34, C<:std> would only apply the first layer provided that is +either C<:utf8> or has a layer argument, e.g. C<:encoding(UTF-8)>. Since +Perl 5.34 it will apply the same layer stack it provides to C<${^OPEN}>. + =head1 IMPLEMENTATION DETAILS There is a class method in C C which is