From: Michael G. Schwern Date: Mon, 6 Oct 2003 13:14:36 +0000 (-0700) Subject: Fixing UNIVERSAL.pm's bit of unpleasantness X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2bfd56816acd10b1f958d1dde1769bafd756cbea;p=p5sagit%2Fp5-mst-13.2.git Fixing UNIVERSAL.pm's bit of unpleasantness Message-Id: <20031006131436.G20960@ttul.org> p4raw-id: //depot/perl@21418 --- diff --git a/lib/UNIVERSAL.pm b/lib/UNIVERSAL.pm index 7b7bfc4..c5f22eb 100644 --- a/lib/UNIVERSAL.pm +++ b/lib/UNIVERSAL.pm @@ -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__ diff --git a/t/op/universal.t b/t/op/universal.t index 71daf67..ebc22d1 100755 --- a/t/op/universal.t +++ b/t/op/universal.t @@ -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 !$@;