Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.98k stars 559 forks source link

IO::File->open should respect use open() #12749

Open p5pRT opened 11 years ago

p5pRT commented 11 years ago

Migrated from rt.perl.org#116599 (status was 'open')

Searchable as RT116599$

p5pRT commented 11 years ago

From michael@negativespace.net

Created by michael@negativespace.net

IO​::File->open() isn't affected by use open(​:std :utf8). I understand that use open() is lexical in scope\, but IO​::File's open could at least present a warning. And if that's not possible the documentation for IO​::File should be changed.

Schwern suggests this is related to autodie\, and can be fixed in a similar manner. If it cannot be fixed\, then an error message or warning would be very welcome (and would have saved a great deal of frustration).

See also​:

http​://stackoverflow.com/questions/14595624/perls-iofile-and-use-open-qwutf8/14595721

https://rt.cpan.org/Public/Bug/Display.html?id=54777

Here is a test case​:

#!/usr/local/bin/perl

use utf8; use v5.16; use strict; use warnings; use warnings qw(FATAL utf8); use diagnostics; use open qw(​:std :utf8); use charnames qw(​:full :short);

use Test​::More tests => 3;

my $str = "Hello ȓ (r-caret)";

eval {   open(my $fh\, '\<'\, \$str);   print while ($_ = $fh->getc());   close($fh);   pass("read utf from opened string"); }; if ($@​) {   fail("read utf8 from opened() string"); }

eval {   use IO​::File;   my $fh = IO​::File->new();   $fh->open(\$str\, '\<');   print while ($_ = $fh->getc());   $fh->close();   pass("read utf8 from IO​::File->open() string"); }; if ($@​) {   fail("read utf8 from IO​::File->open() string"); }

eval {   use IO​::File;   my $fh = IO​::File->new();   $fh->open(\$str\, '\<​:encoding(UTF-8)');   print while ($_ = $fh->getc());   $fh->close();   pass("read utf8 from IO​::File->open() string with encoding"); }; if ($@​) {   fail("read utf8 from IO​::File->open() string with encoding"); }

Perl Info ``` Flags: category=library severity=medium module=IO::File Site configuration information for perl 5.16.2: Configured by michael at Wed Nov 21 10:46:56 PST 2012. Summary of my perl5 (revision 5 version 16 subversion 2) configuration: Platform: osname=darwin, osvers=12.2.0, archname=darwin-2level uname='darwin bernard.local 12.2.0 darwin kernel version 12.2.0: sat aug 25 00:48:52 pdt 2012; root:xnu-2050.18.24~1release_x86_64 x86_64 ' config_args='-de' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/opt/local/include', optimize='-O3', cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/opt/local/include' ccversion='', gccversion='4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/opt/local/lib' libpth=/opt/local/lib /usr/lib libs=-ldbm -ldl -lm -lutil -lc perllibs=-ldl -lm -lutil -lc libc=, so=dylib, useshrplib=false, libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/opt/local/lib -fstack-protector' Locally applied patches: @INC for perl 5.16.2: /usr/local/lib/perl5/site_perl/5.16.2/darwin-2level /usr/local/lib/perl5/site_perl/5.16.2 /usr/local/lib/perl5/5.16.2/darwin-2level /usr/local/lib/perl5/5.16.2 . Environment for perl 5.16.2: DYLD_LIBRARY_PATH=:/usr/local/pgsql/lib HOME=/Users/michael LANG=en_CA LANGUAGE (unset) LC_ALL=C LD_LIBRARY_PATH=:/usr/local/pgsql/lib LOGDIR (unset) PATH=/usr/local/bin:/usr/local/mysql/bin:/usr/local/pgsql/bin:/Users/michael/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/X11/bin:/opt/local/bin:/opt/local/sbin PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 11 years ago

From @Leont

On Wed\, Jan 30\, 2013 at 7​:18 PM\, Michael Joyce \perlbug\-followup@&#8203;perl\.org wrote​:

IO​::File->open() isn't affected by use open(​:std :utf8). I understand that use open() is lexical in scope\, but IO​::File's open could at least present a warning. And if that's not possible the documentation for IO​::File should be changed.

First of all\, why are you using IO​::File? I can't think of any advantage it has over regular open (unless you're still on perl 5.005)\, and many disadvantages (specially poor support for PerlIO layers). You really don't want to use it anymore.

Schwern suggests this is related to autodie\, and can be fixed in a similar manner. If it cannot be fixed\, then an error message or warning would be very welcome (and would have saved a great deal of frustration).

Well yeah\, it probably can. I'm not entirely sure it should\, given IO​::File is visibly non-lexical (unlike autodie\, which acts as if it is lexical).

Leon

p5pRT commented 11 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 11 years ago

From michael@negativespace.net

On 2013-01-30\, at 10​:37 AM\, Leon Timmermans via RT \perlbug\-followup@&#8203;perl\.org wrote​:

On Wed\, Jan 30\, 2013 at 7​:18 PM\, Michael Joyce \perlbug\-followup@&#8203;perl\.org wrote​:

IO​::File->open() isn't affected by use open(​:std :utf8). I understand that use open() is lexical in scope\, but IO​::File's open could at least present a warning. And if that's not possible the documentation for IO​::File should be changed.

First of all\, why are you using IO​::File? I can't think of any advantage it has over regular open (unless you're still on perl 5.005)\, and many disadvantages (specially poor support for PerlIO layers). You really don't want to use it anymore.

I found it while reading the documentation\, and it seemed to do what I needed. If it's depreciated\, I didn't see that mentioned anywhere in the POD or on CPAN.

Schwern suggests this is related to autodie\, and can be fixed in a similar manner. If it cannot be fixed\, then an error message or warning would be very welcome (and would have saved a great deal of frustration).

Well yeah\, it probably can. I'm not entirely sure it should\, given IO​::File is visibly non-lexical (unlike autodie\, which acts as if it is lexical).

Leon

p5pRT commented 11 years ago

From alex.hartmaier@gmail.com

On Wed\, Jan 30\, 2013 at 8​:38 PM\, Michael Joyce \michael@&#8203;negativespace\.netwrote​:

On 2013-01-30\, at 10​:37 AM\, Leon Timmermans via RT \< perlbug-followup@​perl.org> wrote​:

On Wed\, Jan 30\, 2013 at 7​:18 PM\, Michael Joyce \perlbug\-followup@&#8203;perl\.org wrote​:

IO​::File->open() isn't affected by use open(​:std :utf8). I understand that use open() is lexical in scope\, but IO​::File's open could at least present a warning. And if that's not possible the documentation for IO​::File should be changed.

First of all\, why are you using IO​::File? I can't think of any advantage it has over regular open (unless you're still on perl 5.005)\, and many disadvantages (specially poor support for PerlIO layers). You really don't want to use it anymore.

I found it while reading the documentation\, and it seemed to do what I needed. If it's depreciated\, I didn't see that mentioned anywhere in the POD or on CPAN.

I'm working on perlopentut at the moment\, in which doc have you seen IO​::File? perlopentut doesn't mention it.

Schwern suggests this is related to autodie\, and can be fixed in a similar manner. If it cannot be fixed\, then an error message or warning would be very welcome (and would have saved a great deal of frustration).

Well yeah\, it probably can. I'm not entirely sure it should\, given IO​::File is visibly non-lexical (unlike autodie\, which acts as if it is lexical).

Leon

p5pRT commented 11 years ago

From @Leont

On Fri\, Feb 1\, 2013 at 10​:11 PM\, Alexander Hartmaier \alex\.hartmaier@&#8203;gmail\.com wrote​:

I found it while reading the documentation\, and it seemed to do what I needed. If it's depreciated\, I didn't see that mentioned anywhere in the POD or on CPAN.

I'm working on perlopentut at the moment\, in which doc have you seen IO​::File? perlopentut doesn't mention it.

perlfunc open mentions it as an alternative. In general\, it should be updated to modern practices just as much as perlopentut does.

Leon