Permalink
Browse files

Use :utf8 PerlIO layer instead of :encoding(UTF-8)

This is the non-strict version of the encoding, which silences
the warnings reported in evalEmpire/perl5i#163 and doherty/utfu-all#5
  • Loading branch information...
1 parent 5b0ab0c commit 221e994fcd519c5b504c138b8454ead57434f69b @doherty committed Jun 12, 2011
Showing with 20 additions and 13 deletions.
  1. +1 −0 Changes
  2. +1 −1 lib/utf8/all.pm
  3. +12 −0 t/gh-5.t
  4. +2 −3 t/open.t
  5. +4 −9 t/utf8.t
View
@@ -1,6 +1,7 @@
Revision history for Perl module {{$dist->name}}
{{$NEXT}}
+ * Use :utf8 PerlIO layer instead of stricter :encoding(UTF-8) (GH #5)
0.002 2011-04-21
* Add unimport()
View
@@ -50,7 +50,7 @@ sub import {
utf8::import($class);
# utf8 by default on filehandles
- open::import($class, ':encoding(UTF-8)');
+ open::import($class, ':utf8');
open::import($class, ':std');
# utf8 in @ARGV
View
@@ -0,0 +1,12 @@
+#!perl
+# Do a test for GH #5 (schwern/perl5i#163)
+
+use Test::More tests => 1;
+
+SKIP: {
+ eval 'require CGI::Simple';
+ skip "CGI::Simple & Capture::Tiny needed for this: $@", 2 if $@;
@schwern

schwern Sep 25, 2011

Contributor

eval STRING is not necessary here, an eval BLOCK will do.

It's safer to directly check the result of an eval rather than using $@.

skip "CGI::Simple needed for these tests: $@", 2 if !eval { require CGI::Simple };
+
+ my $stdout = qx{$^X -Ilib -e 'use utf8::all; use CGI::Simple; print CGI::Simple->VERSION;' 2>&1};
+ is $stdout, CGI::Simple->VERSION, 'version';
+}
View
@@ -2,14 +2,13 @@
# Test opening an actual file
use utf8::all;
use PerlIO;
-use Test::More tests => 4;
+use Test::More tests => 3;
ok open my $in, '<', 'corpus/testfile';
my @layers = PerlIO::get_layers($in);
+
ok(grep(m/utf8/, @layers), 'utf8 appears in the perlio layers')
or diag explain { $fh => \@layers };
-ok(grep(m/utf-8-strict/, @layers), 'utf-8-strict appears in the perlio layers')
- or diag explain { $fh => \@layers };
my $contents = do { local $/; <$in>};
is $contents, "f\x{f8}\x{f8}\n", 'unicode retrieved OK';
View
@@ -13,29 +13,24 @@ use Test::More;
is length "utf8::all is MËTÁŁ", 18;
# Test the standard handles and all newly opened handles are utf8
- ok open my $test_fh, ">", "perlio_test";
- END { unlink "perlio_test" }
+ ok open my $test_fh, '>', 'perlio_test';
+ END { unlink 'perlio_test' }
for my $fh (*STDOUT, *STDIN, *STDERR, $test_fh) {
my @layers = PerlIO::get_layers($fh);
ok(grep(m/utf8/, @layers), 'utf8 appears in the perlio layers')
or diag explain { $test_fh => \@layers };
- ok(grep(m/utf-8-strict/, @layers), 'utf-8-strict appears in the perlio layers')
- or diag explain { $test_fh => \@layers };
}
}
# And off
{
- ok open my $test_fh, ">", "perlio_test2";
- END { unlink "perlio_test2" }
+ ok open my $test_fh, '>', 'perlio_test2';
+ END { unlink 'perlio_test2' }
my @layers = PerlIO::get_layers($test_fh);
ok( !grep(/utf8/, @layers), q{utf8 doesn't 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})
- or diag explain { $test_fh => \@layers };
-
}
done_testing;

0 comments on commit 221e994

Please sign in to comment.