develooper Front page | perl.perl5.porters | Postings from February 2009

Re: deprecate UNIVERSAL->import

Thread Previous
Nicholas Clark
February 7, 2009 07:13
Re: deprecate UNIVERSAL->import
Message ID:
On Sat, Feb 07, 2009 at 03:38:37PM +0100, Rafael Garcia-Suarez wrote:
> 2009/1/26 Ricardo SIGNES <>:
> >
> > I mean, honestly.
> >
> > There is no reason for to be loaded, as it does two things: set a
> > VERSION and setup an &import.  The import should not be used, as we've been
> > asking people to stop for quite some time now, and it's just a lousy idea.  The
> > VERSION isn't necessary because (a) there's no code to worry about changing and
> > (b) the version is directly determinable from $] outside of blead, anyway.
> >
> > This patch introduces a lexical 'deprecated' warning'.
> Thanks, applied as 1d9f57de1578571277e83372972a28d6d830e713, and I
> also added a test in the next commit. Amazingly, the test suite
> doesn't emit any warning.

I tweaked the first patch:

diff --git a/lib/ b/lib/
index 01a16ca..d0aa1ed 100644
--- a/lib/
+++ b/lib/
@@ -11,12 +11,11 @@ our $VERSION = '1.04';
 require Exporter;
 @EXPORT_OK = qw(isa can VERSION);
-require warnings;
 # Make sure that even though the import method is called, it doesn't do
 # anything unless called on UNIVERSAL.
 sub import {
     return unless $_[0] eq __PACKAGE__;
+    require warnings;
       'UNIVERSAL->import is deprecated and will be removed in a future perl',

We don't want new code getting a crack addition.
Erm, we don't want to create a new side effect of use UNIVERSAL, that code
gets hooked on.

Nicholas Clark

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About