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

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

Thread Previous | Thread Next
Ævar Arnfjörð Bjarmason
September 27, 2016 12:34
Re: I'd like to get rid of "use UNIVERSAL;"
Message ID:
On Mon, Sep 26, 2016 at 10:32 PM, Æ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.

The thing that would break even fewer distros is to make this work:

    use UNIVERSAL;

While making this break:

    use UNIVERSAL qw(can);

That would 100% preserve backwards compatibility, make no new things
die/fail, but just remove "UNIVERSAL::import".

I just couldn't find the part in the core that would allow me to
distinguish between:

    # should not die
    $ perl -wE 'package Foo {}; Foo->import'
    # should die
    $ perl -wE 'package Foo {}; Foo->import(qw(bar))'

I.e. perl will just ignore missing import/unimport routines, that's
the bit in the core I patche (to not ignore them for UNIVERSAL), but
maybe there's a better way.

I guess I'd need to patch pp_entersub for that to work, unless anyone
has better ideas. I.e. check if $pkg eq "UNIVERSAL" and $sub ~~
[qw(import unimport)] on every call, which would be quite nasty.

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