X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fopen.pm;h=32c5118be9db4b17cbe7e5d882eab8ebb86a5b79;hb=78e38bb6033b96ad3fdd5f4f7bd08f6fedae70cb;hp=2dc1d2130c6c93a61dcf058bb357a10e6ab5322e;hpb=fae2c0fbfb26247eb616ab310ef74b1f4084ba68;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/open.pm b/lib/open.pm index 2dc1d21..32c5118 100644 --- a/lib/open.pm +++ b/lib/open.pm @@ -1,9 +1,9 @@ package open; use warnings; use Carp; -$open::hint_bits = 0x20000; +$open::hint_bits = 0x20000; # HINT_LOCALIZE_HH -our $VERSION = '1.01'; +our $VERSION = '1.03'; my $locale_encoding; @@ -27,6 +27,7 @@ sub _get_locale_encoding { } elsif ($ENV{LANG} =~ /^([^.]+)\.([^.]+)$/) { ($country_language, $locale_encoding) = ($1, $2); } + # LANGUAGE affects only LC_MESSAGES only on glibc } elsif (not $locale_encoding) { if ($ENV{LC_ALL} =~ /\butf-?8\b/i || $ENV{LANG} =~ /\butf-?8\b/i) { @@ -40,7 +41,7 @@ sub _get_locale_encoding { # would be excellent!) --jhi } if (defined $locale_encoding && - $locale_encoding eq 'euc' && + lc($locale_encoding) eq 'euc' && defined $country_language) { if ($country_language =~ /^ja_JP|japan(?:ese)?$/i) { $locale_encoding = 'euc-jp'; @@ -50,9 +51,9 @@ sub _get_locale_encoding { $locale_encoding = 'euc-cn'; } elsif ($country_language =~ /^zh_TW|taiwan(?:ese)?$/i) { $locale_encoding = 'euc-tw'; + } else { + croak "Locale encoding 'euc' too ambiguous"; } - croak "Locale encoding 'euc' too ambiguous" - if $locale_encoding eq 'euc'; } } } @@ -79,7 +80,7 @@ sub import { foreach my $layer (split(/\s+/,$dscp)) { $layer =~ s/^://; if ($layer eq 'locale') { - use Encode; + require Encode; _get_locale_encoding() unless defined $locale_encoding; (warnings::warnif("layer", "Cannot figure out an encoding to use"), last) @@ -94,8 +95,8 @@ sub import { my $target = $layer; # the layer name itself $target =~ s/^(\w+)\(.+\)$/$1/; # strip parameters - unless(PerlIO::Layer::->find($target)) { - warnings::warnif("layer", "Unknown PerlIO layer '$layer'"); + unless(PerlIO::Layer::->find($target,1)) { + warnings::warnif("layer", "Unknown PerlIO layer '$target'"); } } push(@val,":$layer"); @@ -165,9 +166,12 @@ Perl is configured to use PerlIO as its IO system (which is now the default). The C pragma serves as one of the interfaces to declare default -"layers" (also known as "disciplines") for all I/O. Any open(), -readpipe() (aka qx//) and similar operators found within the lexical -scope of this pragma will use the declared defaults. +"layers" (also known as "disciplines") for all I/O. Any two-argument +open(), readpipe() (aka qx//) and similar operators found within the +lexical scope of this pragma will use the declared defaults. +Three-argument opens are not affected by this pragma since there you +(can) explicitly specify the layers and are supposed to know what you +are doing. With the C subpragma you can declare the default layers of input streams, and with the C subpragma you can declare @@ -250,7 +254,7 @@ pragma. =back -If your locale environment variables (LANGUAGE, LC_ALL, LC_CTYPE, LANG) +If your locale environment variables (LC_ALL, LC_CTYPE, LANG) contain the strings 'UTF-8' or 'UTF8' (case-insensitive matching), the default encoding of your STDIN, STDOUT, and STDERR, and of B, is UTF-8.