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

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

Thread Previous | Thread Next
From:
Ævar Arnfjörð Bjarmason
Date:
October 11, 2016 23:11
Subject:
Re: I'd like to get rid of "use UNIVERSAL;"
Message ID:
CACBZZX4+n3YJpr1ZkS5R4NfKeak1z5n3+iSY2OawXegZrNT6ig@mail.gmail.com
On Tue, Sep 27, 2016 at 3:47 PM, Aristotle Pagaltzis <pagaltzis@gmx.de> wrote:
> * Ævar Arnfjörð Bjarmason <avarab@gmail.com> [2016-09-27 14:36]:
>> 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))'
>
> Seems easy?
>
>     $ perl -MO=Concise -e'Foo->import'
>     7  <@> leave[1 ref] vKP/REFC ->(end)
>     1     <0> enter ->2
>     2     <;> nextstate(main 1 -e:1) v:{ ->3
>     6     <1> entersub[t1] vKS/TARG ->7
>     3        <0> pushmark s ->4
>     4        <$> const(PV "Foo") sM/BARE ->5
>     5        <$> method_named(PV "import") ->6
>     -e syntax OK
>
>     $ perl -MO=Concise -e'Foo->import(1)'
>     8  <@> leave[1 ref] vKP/REFC ->(end)
>     1     <0> enter ->2
>     2     <;> nextstate(main 1 -e:1) v:{ ->3
>     7     <1> entersub[t1] vKS/TARG ->8
>     3        <0> pushmark s ->4
>     4        <$> const(PV "Foo") sM/BARE ->5
>     5        <$> const(IV 1) sM ->6
>     6        <$> method_named(PV "import") ->7
>     -e syntax OK
>
> If I read this right, the arguments are already on the stack by the time
> that Perl_gv_fetchmethod_pvn_flags gets called.

I tried grepping around but couldn't find this, can you or anyone else
here point out what API I'm supposed to be using in
Perl_gv_fetchmethod_pvn_flags to get at these arguments?

>> 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.
>
> If what I said is right, then you’d need to add a check for whether the
> method is being called with arguments. Then just delete the import sub
> from UNIVERSAL (which leaves the file without any code). That should add
> up to the right thing happening, no?
>
>> 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.
>
> Yeah, too nasty to do it that.
>
> Regards,
> --
> Aristotle Pagaltzis // <http://plasmasturm.org/>

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