summaryrefslogtreecommitdiff
path: root/dist/IO
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-04-14 06:19:07 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-04-14 06:19:07 -0700
commit221e5dbc861edab87d502b2e8d85f5310d0fd1e4 (patch)
treed8a08d9dc494628f169a2665358c88b227092ec8 /dist/IO
parent6e925ecb7bdbde03e6b1c74f119c1d7cc612cd00 (diff)
downloadperl-221e5dbc861edab87d502b2e8d85f5310d0fd1e4.tar.gz
[perl #88486] IO::File does not always export SEEK*
Commit d963bf0 made perl set @IO::File::ISA automagically. Commit 15e6cdd made filehandle methods load IO::File automagically. Commit efc5c7c attempted to solve the problem that having IO::Handle loaded causes IO::File to be bypassed, rendering 15e6cdd only semi-effective (see [perl #87940]), by requiring IO::File inside IO::Handle. That commit ended up breaking several CPAN modules, because IO::File adds @IO::Seekable::EXPORT to its own exports. If IO::Seekable is loaded first (before IO::File), before setting up its @EXPORT it loads IO::Handle, which loads IO::File, which tries to load IO::Seekable, which is in %INC already, and which is hence wait- ing for IO::File to load before it sets its own @EXPORT. So IO::File sees @IO::Seekable::EXPORT empty. Hence, every piece of code that tries to import SEEK_END from IO::File will simply not get it if IO::Seekable is already loaded (explicitly or, e.g., by File::Temp). This commit hopefully fixes the breakage and the problem that efc5c7c attempted to fix by loading IO::File only inside IO::Handle::new (the only method that IO::File overrides).
Diffstat (limited to 'dist/IO')
-rw-r--r--dist/IO/lib/IO/Handle.pm19
-rw-r--r--dist/IO/t/io_file_export.t18
2 files changed, 30 insertions, 7 deletions
diff --git a/dist/IO/lib/IO/Handle.pm b/dist/IO/lib/IO/Handle.pm
index a7431faabd..6ca3c8a35d 100644
--- a/dist/IO/lib/IO/Handle.pm
+++ b/dist/IO/lib/IO/Handle.pm
@@ -265,12 +265,6 @@ use Symbol;
use SelectSaver;
use IO (); # Load the XS module
-# Since perl will automatically require IO::File if needed, but also
-# initialises IO::File's @ISA as part of the core we must ensure
-# IO::File is loaded if IO::Handle is. This avoids effectively
-# "half-loading" IO::File.
-require IO::File;
-
require Exporter;
@ISA = qw(Exporter);
@@ -315,7 +309,18 @@ $VERSION = eval $VERSION;
sub new {
my $class = ref($_[0]) || $_[0] || "IO::Handle";
- @_ == 1 or croak "usage: $class->new()";
+ if (@_ != 1) {
+ # Since perl will automatically require IO::File if needed, but
+ # also initialises IO::File's @ISA as part of the core we must
+ # ensure IO::File is loaded if IO::Handle is. This avoids effect-
+ # ively "half-loading" IO::File.
+ if ($] > 5.013 && $class eq 'IO::File' && !$INC{"IO/File.pm"}) {
+ require IO::File;
+ shift;
+ return IO::File::->new(@_);
+ }
+ croak "usage: $class->new()";
+ }
my $io = gensym;
bless $io, $class;
}
diff --git a/dist/IO/t/io_file_export.t b/dist/IO/t/io_file_export.t
new file mode 100644
index 0000000000..3d11990f13
--- /dev/null
+++ b/dist/IO/t/io_file_export.t
@@ -0,0 +1,18 @@
+#!./perl -w
+
+# This script checks that IO::File exports the SEEK* constants if
+# IO::Seekable is loaded first, which was temporarily broken during 5.14
+# code freeze. See [perl #88486].
+
+BEGIN{
+ require($ENV{PERL_CORE} ? "../../t/test.pl" : "./t/test.pl");
+ plan(tests => 3);
+}
+
+use IO::Seekable (); # import nothing
+use IO::File; # import defaults
+
+# No strict!
+cmp_ok SEEK_END, 'ne', "SEEK_END", 'SEEK_END';
+cmp_ok SEEK_SET, 'ne', "SEEK_SET", 'SEEK_SET';
+cmp_ok SEEK_CUR, 'ne', "SEEK_CUR", 'SEEK_CUR';