Yitzchak points out that this function argument is NULLOK
[p5sagit/p5-mst-13.2.git] / lib / open.pm
index 092ec48..3565762 100644 (file)
@@ -1,22 +1,22 @@
 package open;
 use warnings;
-use Carp;
 $open::hint_bits = 0x20000; # HINT_LOCALIZE_HH
 
-our $VERSION = '1.04';
+our $VERSION = '1.04_01';
 
 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;
 }
 
+sub croak {
+    require Carp; goto &Carp::croak;
+}
+
 sub _drop_oldenc {
     # If by the time we arrive here there already is at the top of the
     # perlio layer stack an encoding identical to what we would like
@@ -39,15 +39,14 @@ sub _drop_oldenc {
     return unless @old >= 3 &&
                  $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;
-       Carp::croak("open: Unknown encoding '$loname'");
+       croak("open: Unknown encoding '$loname'");
     }
     my ($voname, $vcname) = _get_encname($new[-1]);
     unless (defined $vcname) {
-       require Carp;
-       Carp::croak("open: Unknown encoding '$voname'");
+       croak("open: Unknown encoding '$voname'");
     }
     if ($lcname eq $vcname) {
        binmode($h, ":pop"); # utf8 is part of the encoding layer
@@ -77,7 +76,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;