Skip to content

STDERR PerlIO layers are not preserved #47

@kamholz

Description

@kamholz

Setting binmode STDERR, ':encoding(UTF-8)' is not always preserved when using Capture::Tiny. The docs say it tries to do this, but evidently it doesn't succeed. The following test case demonstrates the error on version 0.44, Perl 5.24.0:

use strict;
use warnings;
use utf8;
use Capture::Tiny qw(capture capture_stdout);
use Data::Dumper;
binmode STDOUT, ':encoding(UTF-8)';
binmode STDERR, ':encoding(UTF-8)';

my $output = capture_stdout { print "eng-rus-Тверитнев\neng-rus-Тверитнев\neng-rus-Тверитнев" };

foreach my $file (split /\n/, $output) {
    print Dumper([ 1, PerlIO::get_layers(STDERR) ]);
    print STDERR $file, "\n";
    print Dumper([ 2, PerlIO::get_layers(STDERR) ]);
    my ($foo) = capture { print $file };
    print Dumper([ 3, PerlIO::get_layers(STDERR) ]);
}

The resulting output shows several "Wide character in print" warnings, and that the PerlIO layers are reset:

$VAR1 = [
          1,
          'unix',
          'perlio',
          'encoding(utf-8-strict)',
          'utf8'
        ];
Wide character in print at test.pl line 13.
eng-rus-Тверитнев
$VAR1 = [
          2,
          'unix',
          'perlio',
          'encoding(utf-8-strict)',
          'utf8'
        ];
$VAR1 = [
          3,
          'unix',
          'perlio'
        ];
$VAR1 = [
          1,
          'unix',
          'perlio'
        ];
Wide character in print at test.pl line 13.
eng-rus-Тверитнев
$VAR1 = [
          2,
          'unix',
          'perlio'
        ];
$VAR1 = [
          3,
          'unix',
          'perlio'
        ];
$VAR1 = [
          1,
          'unix',
          'perlio'
        ];
Wide character in print at test.pl line 13.
eng-rus-Тверитнев
$VAR1 = [
          2,
          'unix',
          'perlio'
        ];
$VAR1 = [
          3,
          'unix',
          'perlio'
        ];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions