develooper Front page | perl.perl5.porters | Postings from September 2016

Re: I'd like to get rid of "use UNIVERSAL;"

Thread Previous | Thread Next
From:
David Cantrell
Date:
September 27, 2016 11:23
Subject:
Re: I'd like to get rid of "use UNIVERSAL;"
Message ID:
20160927112332.GA19611@bytemark.barnyard.co.uk
On Mon, Sep 26, 2016 at 10:32:11PM +0200, ?var Arnfj?r? Bjarmason wrote:

> I've just pushed a smoke-me branch to remote UNIVERSAL::import from
> that package, and make its (no)?import a fatal error via a hack to
> gv.c: http://perl5.git.perl.org/perl.git/commitdiff/8804321d
> 
> The motivation here is that someone doing "use UNIVERSAL;" in some
> module shouldn't make $pkg->can("import") true for any value of $pkg
> in your program.
> 
> But technically this does break backwards compatibility without a
> deprecation cycle. Because "use UNIVERSAL;" isn't an error today, and
> some code on the CPAN redundantly uses that.

You'll also break this:

  use UNIVERSAL;
  ...
  if(UNIVERSAL::isa($foo, 'Some::Class')) { ...

which is a lot more convenient than checking to see if $foo is blessed,
and if it is calling $foo->isa().

That said, it's not a particularly common idiom and I'm happy to change
it in my code.

-- 
David Cantrell | Cake Smuggler Extraordinaire

  "Cynical" is a word used by the naive to describe the experienced.
      George Hills, in uknot

Thread Previous | Thread Next


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