diff options
author | Pradeep Hodigere <phodigere@yahoo.com> | 2003-05-19 09:05:47 -0700 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2003-05-29 09:11:30 +0000 |
commit | 73829507ddd98ed852e6dee8db16197bccfe514a (patch) | |
tree | 3005d0062bc48bc397bc7f2a41c10e3b4ba80fda /ext/IO | |
parent | 8e11cd2b6971dafecaf9e97b12c3f527025bae90 (diff) | |
download | perl-73829507ddd98ed852e6dee8db16197bccfe514a.tar.gz |
[patch] IO::File->open() with encoding
Message-ID: <20030519230547.39731.qmail@web12302.mail.yahoo.com>
p4raw-id: //depot/perl@19634
Diffstat (limited to 'ext/IO')
-rw-r--r-- | ext/IO/lib/IO/File.pm | 8 | ||||
-rw-r--r-- | ext/IO/lib/IO/t/io_utf8.t | 33 |
2 files changed, 41 insertions, 0 deletions
diff --git a/ext/IO/lib/IO/File.pm b/ext/IO/lib/IO/File.pm index 9c4177a6a1..c90eb37a4c 100644 --- a/ext/IO/lib/IO/File.pm +++ b/ext/IO/lib/IO/File.pm @@ -71,6 +71,8 @@ Otherwise, it is returned to the caller. =item open( FILENAME [,MODE [,PERMS]] ) +=item open( FILENAME, IOLAYERS ) + C<open> accepts one, two or three parameters. With one parameter, it is just a front end for the built-in C<open> function. With two or three parameters, the first parameter is a filename that may include @@ -85,6 +87,9 @@ If C<IO::File::open> is given a numeric mode, it passes that mode and the optional permissions value to the Perl C<sysopen> operator. The permissions default to 0666. +If C<IO::File::open> is given a mode that includes the C<:> character, +it passes all the three arguments to the three-argument C<open> operator. + For convenience, C<IO::File> exports the O_XXX constants from the Fcntl module, if this module is available. @@ -157,6 +162,9 @@ sub open { if ($mode =~ /^\d+$/) { defined $perms or $perms = 0666; return sysopen($fh, $file, $mode, $perms); + } elsif ($mode =~ /:/) { + return open($fh, $mode, $file) if @_ == 3; + croak 'usage: $fh->open(FILENAME, IOLAYERS)'; } if (defined($file) && length($file) && ! File::Spec->file_name_is_absolute($file)) diff --git a/ext/IO/lib/IO/t/io_utf8.t b/ext/IO/lib/IO/t/io_utf8.t new file mode 100644 index 0000000000..7c87dc747f --- /dev/null +++ b/ext/IO/lib/IO/t/io_utf8.t @@ -0,0 +1,33 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + unless (find PerlIO::Layer 'perlio') { + print "1..0 # Skip: not perlio\n"; + exit 0; + } +} + +require "./test.pl"; + +plan(tests => 5); + +my $io; + +use_ok('IO::File'); + +$io = IO::File->new; + +ok($io->open("io_utf8", ">:utf8"), "open >:utf8"); +ok((print $io chr(256)), "print chr(256)"); +undef $io; + +$io = IO::File->new; +ok($io->open("io_utf8", "<:utf8"), "open <:utf8"); +is(ord(<$io>), 256, "readline chr(256)"); +undef $io; + +END { + 1 while unlink "io_utf8"; +} |