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

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

Thread Next
Paul "LeoNerd" Evans
June 24, 2022 15:44
Pre-RFC: A built-in ability for lexical import/export
Message ID:
One of the offshoots from the Pre-RFC rejections of the `module` and
`UNIVERSAL::import` ideas, was the thought that perl core really needs
to provide some nicer ways to implement lexical import into the
caller's lexical namespace.

Core didn't really have any code that does lexical import of normal
symbols, so when I created the `builtin::import` function I had to
create it all specially. It's fine there but feels a bit weird not
providing that as a general mechanism for others to use.

I was thinking that maybe it should be just exposed as a builtin::
function itself, perhaps as

  builtin::lexically_export $name, \&func;

Perhaps it should take a whole kv-list of name/ref pairs, so you can
export lots in one go:

    one => \&one,
    two => \&two, ...

Though maybe it would be bad to encourage that because really the
caller ought to be specifying just a few symbols they want. Hmm.

Also, while syntactically this is written out "like a normal function"
and thus could go in `builtin::`, I wonder if it's a good fit here. It
can only possibly work during BEGIN time, because it affects the
compiletime lexical environment of the code being compiled. It isn't
useful at runtime. It syntactically looks like a regular function but
it doesn't really behave like one.

We probably do want this available as a core function, but what should
it be named? Is `builtin::` still a good place to put it?

Paul "LeoNerd" Evans      |  |

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