Skip to content

Commit

Permalink
Document that the -Ci, -Co, and -CD options have file scope
Browse files Browse the repository at this point in the history
While the other -C settings are global, "i" and "o" only affect subsequent
open() calls in the current file. Document this and add two tests to
make sure the documented behaviour doesn't change accidentally.
  • Loading branch information
ntyni authored and Father Chrysostomos committed Nov 5, 2010
1 parent 20f7624 commit 88770b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
10 changes: 5 additions & 5 deletions pod/perlrun.pod
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ STDOUT and STDERR. Repeating letters is just redundant, not cumulative
nor toggling.

The C<io> options mean that any subsequent open() (or similar I/O
operations) will have the C<:utf8> PerlIO layer implicitly applied
to them, in other words, UTF-8 is expected from any input stream,
and UTF-8 is produced to any output stream. This is just the default,
with explicit layers in open() and with binmode() one can manipulate
streams as usual.
operations) in the current file scope will have the C<:utf8> PerlIO layer
implicitly applied to them, in other words, UTF-8 is expected from any
input stream, and UTF-8 is produced to any output stream. This is just
the default, with explicit layers in open() and with binmode() one can
manipulate streams as usual.

C<-C> on its own (not followed by any number or option list), or the
empty string C<""> for the C<PERL_UNICODE> environment variable, has the
Expand Down
17 changes: 16 additions & 1 deletion t/run/switchC.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ BEGIN {

BEGIN { require "./test.pl"; }

plan(tests => 11);
plan(tests => 13);

my $r;

my $tmpfile = tempfile();
my $scriptfile = tempfile();

my $b = pack("C*", unpack("U0C*", pack("U",256)));

Expand Down Expand Up @@ -58,6 +59,20 @@ $r = runperl( switches => [ '-Ci', '-w' ],
stderr => 1 );
like( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input' );

open(S, ">$scriptfile") or die("open $scriptfile: $!");
print S "open(F, q(<$tmpfile)); print ord(<F>); close F";
close S;

$r = runperl( switches => [ '-Ci', '-w' ],
progfile => $scriptfile,
stderr => 1 );
like( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input affects the current file' );

$r = runperl( switches => [ '-Ci', '-w' ],
prog => "do q($scriptfile)",
stderr => 1 );
unlike( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input has file scope' );

$r = runperl( switches => [ '-CA', '-w' ],
prog => 'print ord shift',
stderr => 1,
Expand Down

0 comments on commit 88770b4

Please sign in to comment.