From: Pradeep Hodigere Date: Mon, 19 May 2003 16:05:47 +0000 (-0700) Subject: [patch] IO::File->open() with encoding X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=73829507ddd98ed852e6dee8db16197bccfe514a;p=p5sagit%2Fp5-mst-13.2.git [patch] IO::File->open() with encoding Message-ID: <20030519230547.39731.qmail@web12302.mail.yahoo.com> p4raw-id: //depot/perl@19634 --- diff --git a/MANIFEST b/MANIFEST index c95f376..43d866f 100644 --- a/MANIFEST +++ b/MANIFEST @@ -469,6 +469,7 @@ ext/IO/lib/IO/t/io_taint.t See if the untaint method from IO works ext/IO/lib/IO/t/io_tell.t See if seek()/tell()-related methods from IO work ext/IO/lib/IO/t/io_udp.t See if UDP socket-related methods from IO work ext/IO/lib/IO/t/io_unix.t See if UNIX socket-related methods from IO work +ext/IO/lib/IO/t/io_utf8.t See if perlio opens work ext/IO/lib/IO/t/io_xs.t See if XSUB methods from IO work ext/IO/Makefile.PL IO extension makefile writer ext/IO/poll.c IO poll() emulation using select() diff --git a/ext/IO/lib/IO/File.pm b/ext/IO/lib/IO/File.pm index 9c4177a..c90eb37 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 accepts one, two or three parameters. With one parameter, it is just a front end for the built-in C function. With two or three parameters, the first parameter is a filename that may include @@ -85,6 +87,9 @@ If C is given a numeric mode, it passes that mode and the optional permissions value to the Perl C operator. The permissions default to 0666. +If C is given a mode that includes the C<:> character, +it passes all the three arguments to the three-argument C operator. + For convenience, C 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 0000000..7c87dc7 --- /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"; +}