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

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

Thread Previous
From:
ilmari
Date:
September 27, 2016 12:29
Subject:
Re: I'd like to get rid of "use UNIVERSAL;"
Message ID:
d8jponpv84z.fsf@dalvik.ping.uio.no
David Cantrell <david@cantrell.org.uk> writes:

> On Tue, Sep 27, 2016 at 12:39:58PM +0100, Dagfinn Ilmari Manns?ker wrote:
>> David Cantrell <david@cantrell.org.uk> writes:
>> > On Mon, Sep 26, 2016 at 10:32:11PM +0200, ?var Arnfj?r? Bjarmason wrote:
>> >> 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')) { ...
>> This continues to "work"
>
> The proposal is to make it not work.

I meant the UNIVERSAL::isa() (anti-)idiom would continue to work.  You'd
have to remove 'use UNIVERSAL;', but that wouldn't break anything on
older perls, because this:

>>                          and never required 'use UNIVERSAL', since the
>> function is provided by universal.c, not UNIVERSAL.pm.
>
> I doubt that many people are aware of that, and that even fewer of them
> understand what that means.

The documentation for UNIVERSAL has never implied that you need to load
it other than (in the past) to import the functions.  The WARNINGS
section in fact says:

    You do not need to "use UNIVERSAL" to make these methods available
    to your program (and you should not do so).

> Anyway, the string 'use UNIVERAL;' appears in 74 dists on the CPAN
> according to grep.cpan.me. At least some of them are completely
> redundant in that the file that includes it doesn't also include a call
> to UNIVERSAL::isa or its friends (presumably it used to in an earlier
> version and the 'use' hasn't been deleted), but not all are.

'use UNIVERSAL;' without an import list has _always_ been completely
redundant.

-- 
- Twitter seems more influential [than blogs] in the 'gets reported in
  the mainstream press' sense at least.               - Matt McLeod
- That'd be because the content of a tweet is easier to condense down
  to a mainstream media article.                      - Calle Dybedahl


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