develooper Front page | perl.perl5.porters | Postings from June 2022

Re: Pre-RFC: A built-in ability for lexical import/export

Thread Previous | Thread Next
From:
Dagfinn Ilmari Mannsåker
Date:
June 28, 2022 10:12
Subject:
Re: Pre-RFC: A built-in ability for lexical import/export
Message ID:
877d51ksfw.fsf@wibble.ilmari.org
Martijn Lievaart <m@rtij.nl> writes:

> Op 27-06-2022 om 21:45 schreef Paul "LeoNerd" Evans:
>> On Mon, 27 Jun 2022 19:46:54 +0200
>> Martijn Lievaart <m@rtij.nl> wrote:
>>
>>> What I do not understand is why one would want to use a different
>>> external name than the internal name? Exporter doesn't work like this
>>> and I for one, never felt the need to export under a different name.
>> I'm not sure I follow the question...
>>
>
> If I understand the proposal correctly, you could do:
>
> 	builtin::lexically_export two => \&one;
>
> 	builtin::lexically_export three => \&two;
>
>
> Why not implement:
>
> 	builtin::lexically_export '\&one';
>
> And have that export the sub one() under the name 'one'?

That would only work if one() was a packge sub or variable in the
exporting module, since it would have to be looked up by name.  The
whole point of this is to get away from package subs and variables, so
the item to be exported needs to be passed as a proper reference.

It could be possible to default the name to the (unqualified part of
the) name of the variable (using mechanisms similar to
Sub::Util::subname() and PadWalker::var_name()), but that strikes me as
Too Much Magic™ to avoid a tiny bit of explicitness.

> TIA,
> M4

- ilmari

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