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

Re: deprecate UNIVERSAL->import

Thread Previous
From:
Nicholas Clark
Date:
February 7, 2009 07:13
Subject:
Re: deprecate UNIVERSAL->import
Message ID:
20090207151300.GJ81285@plum.flirble.org
On Sat, Feb 07, 2009 at 03:38:37PM +0100, Rafael Garcia-Suarez wrote:
> 2009/1/26 Ricardo SIGNES <perl.p5p@rjbs.manxome.org>:
> >
> > I mean, honestly.
> >
> > There is no reason for UNIVERSAL.pm 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/UNIVERSAL.pm b/lib/UNIVERSAL.pm
index 01a16ca..d0aa1ed 100644
--- a/lib/UNIVERSAL.pm
+++ b/lib/UNIVERSAL.pm
@@ -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;
     warnings::warnif(
       'deprecated',
       '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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About