Fixing UNIVERSAL.pm's bit of unpleasantness
authorMichael G. Schwern <schwern@pobox.com>
Mon, 6 Oct 2003 13:14:36 +0000 (06:14 -0700)
committerAbhijit Menon-Sen <ams@wiw.org>
Tue, 7 Oct 2003 03:59:38 +0000 (03:59 +0000)
Message-Id: <20031006131436.G20960@ttul.org>

p4raw-id: //depot/perl@21418

lib/UNIVERSAL.pm
t/op/universal.t

index 7b7bfc4..c5f22eb 100644 (file)
@@ -9,9 +9,15 @@ our $VERSION = '1.01';
 # Exporter.  It's bad enough that all classes have a import() method
 # whenever UNIVERSAL.pm is loaded.
 require Exporter;
-*import = \&Exporter::import;
 @EXPORT_OK = qw(isa can VERSION);
 
+# Make sure that even though the import method is called, it doesn't do
+# anything unless its called on UNIVERSAL
+sub import {
+    return unless $_[0] eq __PACKAGE__;
+    goto &Exporter::import;
+}
+
 1;
 __END__
 
index 71daf67..ebc22d1 100755 (executable)
@@ -9,7 +9,7 @@ BEGIN {
     $| = 1;
 }
 
-print "1..100\n";
+print "1..101\n";
 
 $a = {};
 bless $a, "Bob";
@@ -195,3 +195,9 @@ test ! UNIVERSAL::isa("\xff\xff\xff\0", 'HASH');
 my $x = {}; bless $x, 'X';
 test $x->isa('UNIVERSAL');
 test $x->isa('UNIVERSAL');
+
+
+# Check that the "historical accident" of UNIVERSAL having an import()
+# method doesn't effect anyone else.
+eval { Some::Package->import("bar") };
+test !$@;