diff --git a/lib/utf8/all.pm b/lib/utf8/all.pm index 3aa3244..a7727b2 100644 --- a/lib/utf8/all.pm +++ b/lib/utf8/all.pm @@ -87,21 +87,11 @@ C file handles is always global! =head2 UTF-8 Errors -By default, C will handle invalid code points (i.e., -utf-8 that does not map to a valid unicode "character"), as a fatal -error. - -Note: On Perl < v5.24.0 a bug in handling the I/O encoding layers in -combination with threads (and, on Windows, forks) causes a -segmentation fault. To prevent this, C will use the -non-strict C<:utf8> instead of C<:encoding(UTF-8)> for I/O in case of -a thread enabled Perl < 5.24.0. If threads are not enabled for your -Perl version, or if you are using a version >= v5.24.0, C -will use the strict (and recommended) C<:encoding(UTF-8)> I/O layer. - -Note: For C, C, and C, one can decide how -decoding errors are handled by setting the attribute -L. +C will handle invalid code points (i.e., utf-8 that does +not map to a valid unicode "character"), as a fatal error. + +For C, C, and C, one can change this +behaviour by setting the attribute L. =head1 COMPATIBILITY @@ -153,6 +143,9 @@ C, C. =cut +use Encode (); +use PerlIO::utf8_strict; + our $UTF8_CHECK = Encode::FB_CROAK; # Die on encoding errors # UTF-8 Encoding object @@ -164,18 +157,15 @@ sub import { # Enable features/pragmas in calling package my $target = caller; - my $utf8_IO_encoding = $class->_choose_utf8_IO_encoding; - 'utf8'->import::into($target); - 'open'->import::into($target => "IO" => $utf8_IO_encoding); + 'open'->import::into($target, 'IO' => ':utf8_strict'); # use open ':std' only works with some encodings. state $have_encoded_std = 0; - if( !$have_encoded_std ) { - binmode STDERR, $utf8_IO_encoding; - binmode STDOUT, $utf8_IO_encoding; - binmode STDIN, $utf8_IO_encoding; - $have_encoded_std = 1; + if (!$have_encoded_std++) { + binmode STDERR, ':utf8_strict'; + binmode STDOUT, ':utf8_strict'; + binmode STDIN, ':utf8_strict'; } 'charnames'->import::into($target, qw{:full :short}); @@ -277,15 +267,6 @@ sub _utf8_glob { } } -sub _choose_utf8_IO_encoding { - # Perl >= 5.24.0 or no threads? No problem. - return ':encoding(UTF-8)' if $^V >= v5.24.0 || (!$Config{usethreads} && !$Config{useithreads}); - - # A safe default. - require PerlIO::utf8_strict; - return ':utf8_strict'; -} - =head1 INTERACTION WITH AUTODIE If you use L, which is a great idea, you need to use at least diff --git a/t/utf8.t b/t/utf8.t index 9b1930d..fc1e8a8 100644 --- a/t/utf8.t +++ b/t/utf8.t @@ -37,10 +37,10 @@ use Test::More; # If we have the Perl Unicode flag set that adds the UTF-8 layer, # we need to skip this test. skip 'Perl Unicode flag set that always adds UTF-8 layer to output', 1 if (${^UNICODE} & 16); - ok( !grep(/utf8/, @layers), q{utf8 doesn't appear in perlio layers}) + ok(!grep(/utf8/, @layers), q{utf8 does not appear in perlio layers}) or diag explain { $test_fh => \@layers }; } - ok( !grep(m/utf-?8[-_]strict/, @layers), q{utf-?8[-_]strict doesn't appear in the perlio layers}) + ok(!grep(m/utf-?8[-_]strict/, @layers), q{utf-?8[-_]strict does not appear in the perlio layers}) or diag explain { $test_fh => \@layers }; }