This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix leak in /[(?{]/
[perl5.git] / lib / open.pm
index 74119ca..ca3cf7b 100644 (file)
@@ -1,7 +1,7 @@
 package open;
 use warnings;
 
-our $VERSION = '1.07';
+our $VERSION = '1.11';
 
 require 5.008001; # for PerlIO::get_layers()
 
@@ -95,16 +95,22 @@ sub import {
            }
        }
        if ($type eq 'IN') {
-           _drop_oldenc(*STDIN, @val);
+           _drop_oldenc(*STDIN, @val) if $std;
            $in  = join(' ', @val);
        }
        elsif ($type eq 'OUT') {
-           _drop_oldenc(*STDOUT, @val);
+           if ($std) {
+               _drop_oldenc(*STDOUT, @val);
+               _drop_oldenc(*STDERR, @val);
+           }
            $out = join(' ', @val);
        }
        elsif ($type eq 'IO') {
-           _drop_oldenc(*STDIN,  @val);
-           _drop_oldenc(*STDOUT, @val);
+           if ($std) {
+               _drop_oldenc(*STDIN, @val);
+               _drop_oldenc(*STDOUT, @val);
+               _drop_oldenc(*STDERR, @val);
+           }
            $in = $out = join(' ', @val);
        }
        else {
@@ -147,7 +153,7 @@ open - perl pragma to set default PerlIO layers for input and output
 
     use open IO  => ':locale';
 
-    use open ':encoding(utf8)';
+    use open ':encoding(UTF-8)';
     use open ':locale';
     use open ':encoding(iso-8859-7)';
 
@@ -189,8 +195,8 @@ For example:
 
 These are equivalent
 
-    use open ':encoding(utf8)';
-    use open IO => ':encoding(utf8)';
+    use open ':encoding(UTF-8)';
+    use open IO => ':encoding(UTF-8)';
 
 as are these
 
@@ -207,14 +213,16 @@ many encodings have several aliases.  See L<Encode::Supported> for
 details and the list of supported locales.
 
 When open() is given an explicit list of layers (with the three-arg
-syntax), they override the list declared using this pragma.
+syntax), they override the list declared using this pragma.  open() can
+also be given a single colon (:) for a layer name, to override this pragma
+and use the default (C<:raw> on Unix, C<:crlf> on Windows).
 
 The C<:std> subpragma on its own has no effect, but if combined with
 the C<:utf8> or C<:encoding> subpragmas, it converts the standard
 filehandles (STDIN, STDOUT, STDERR) to comply with encoding selected
 for input/output handles.  For example, if both input and out are
-chosen to be C<:encoding(utf8)>, a C<:std> will mean that STDIN, STDOUT,
-and STDERR are also in C<:encoding(utf8)>.  On the other hand, if only
+chosen to be C<:encoding(UTF-8)>, a C<:std> will mean that STDIN, STDOUT,
+and STDERR are also in C<:encoding(UTF-8)>.  On the other hand, if only
 output is chosen to be in C<< :encoding(koi8r) >>, a C<:std> will cause
 only the STDOUT and STDERR to be in C<koi8r>.  The C<:locale> subpragma
 implicitly turns on C<:std>.