Quotes fixed, see also perl #36079
[p5sagit/p5-mst-13.2.git] / lib / open.pm
index 35d33dd..4515899 100644 (file)
@@ -7,13 +7,10 @@ our $VERSION = '1.04';
 
 require 5.008001; # for PerlIO::get_layers()
 
-use Encode qw(resolve_alias);
-
-use encoding ':_get_locale_encoding';
-my $locale_encoding = _get_locale_encoding();
+my $locale_encoding;
 
 sub _get_encname {
-    return ($1, resolve_alias($1)) if $_[0] =~ /^:?encoding\((.+)\)$/;
+    return ($1, Encode::resolve_alias($1)) if $_[0] =~ /^:?encoding\((.+)\)$/;
     return;
 }
 
@@ -37,8 +34,9 @@ sub _drop_oldenc {
     return unless @new >= 1 && $new[-1] =~ /^:encoding\(.+\)$/;
     my @old = PerlIO::get_layers($h);
     return unless @old >= 3 &&
-                 $old[-1] eq 'utf8';
+                 $old[-1] eq 'utf8' &&
                   $old[-2] =~ /^encoding\(.+\)$/;
+    require Encode;
     my ($loname, $lcname) = _get_encname($old[-2]);
     unless (defined $lcname) { # Should we trust get_layers()?
        require Carp;
@@ -77,7 +75,8 @@ sub import {
             $layer =~ s/^://;
            if ($layer eq 'locale') {
                require Encode;
-               $locale_encoding = _get_locale_encoding()
+               require encoding;
+               $locale_encoding = encoding::_get_locale_encoding()
                    unless defined $locale_encoding;
                (warnings::warnif("layer", "Cannot figure out an encoding to use"), last)
                    unless defined $locale_encoding;