This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
The ${"\cTAINT"} raises the ire of 'use strict'.
[perl5.git] / lib / open.pm
index 8eff354..d8a6350 100644 (file)
@@ -10,9 +10,13 @@ sub in_locale { $^H & $locale::hint_bits }
 
 sub _get_locale_encoding {
     unless (defined $locale_encoding) {
-       eval { use I18N::Langinfo qw(langinfo CODESET) };
+       eval {
+           # I18N::Langinfo isn't available everywhere
+           require I18N::Langinfo;
+           I18N::Langinfo->import('langinfo', 'CODESET');
+       };
        unless ($@) {
-           $locale_encoding = langinfo(CODESET);
+           $locale_encoding = langinfo(CODESET());
        }
        my $country_language;
         if (not $locale_encoding && in_locale()) {
@@ -26,17 +30,17 @@ sub _get_locale_encoding {
            # parts of LC_ALL and LANG (the parts before the dot (if any)),
            # since we have Locale::Country and Locale::Language available.
            # TODO: get a database of Language -> Encoding mappings
-           # (the Estonian database would be excellent!)
-           # --jhi
+           # (the Estonian database at http://www.eki.ee/letter/
+           # would be excellent!) --jhi
        }
        if (defined $locale_encoding &&
            $locale_encoding eq 'euc' &&
            defined $country_language) {
-           if ($country_language =~ /^ja_JP|japan(?:ese)$/i) {
+           if ($country_language =~ /^ja_JP|japan(?:ese)?$/i) {
                $locale_encoding = 'eucjp';
-           } elsif ($country_language =~ /^ko_KR|korea(?:n)$/i) {
+           } elsif ($country_language =~ /^ko_KR|korean?$/i) {
                $locale_encoding = 'euckr';
-           } elsif ($country_language =~ /^zh_TW|taiwan(?:ese)$/i) {
+           } elsif ($country_language =~ /^zh_TW|taiwan(?:ese)?$/i) {
                $locale_encoding = 'euctw';
            }
            croak "Locale encoding 'euc' too ambiguous"
@@ -49,9 +53,7 @@ sub import {
     my ($class,@args) = @_;
     croak("`use open' needs explicit list of disciplines") unless @args;
     $^H |= $open::hint_bits;
-    my ($in,$out) = split(/\0/,(${^OPEN} || '\0'));
-    my @in  = split(/\s+/,$in);
-    my @out = split(/\s+/,$out);
+    my ($in,$out) = split(/\0/,(${^OPEN} || "\0"), -1);
     while (@args) {
        my $type = shift(@args);
        my $discp = shift(@args);
@@ -69,15 +71,17 @@ sub import {
                } else {
                    $layer = "encoding($locale_encoding)";
                }
-           }
-           unless(PerlIO::Layer::->find($layer)) {
-               carp("Unknown discipline layer '$layer'");
+           } else {
+               unless(PerlIO::Layer::->find($layer)) {
+                   carp("Unknown discipline layer '$layer'");
+               }
            }
            push(@val,":$layer");
            if ($layer =~ /^(crlf|raw)$/) {
                $^H{"open_$type"} = $layer;
            }
        }
+       # print "# type = $type, val = @val\n";
        if ($type eq 'IN') {
            $in  = join(' ',@val);
        }
@@ -152,6 +156,7 @@ level.
 
 =head1 SEE ALSO
 
-L<perlfunc/"binmode">, L<perlfunc/"open">, L<perlunicode>, L<PerlIO>
+L<perlfunc/"binmode">, L<perlfunc/"open">, L<perlunicode>, L<PerlIO>,
+L<encoding>
 
 =cut