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

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

Thread Previous
Ricardo Signes
June 24, 2022 16:19
Re: Pre-RFC: A built-in ability for lexical import/export
Message ID:
On Fri, Jun 24, 2022, at 11:44, Paul "LeoNerd" Evans wrote:
> Perhaps it should take a whole kv-list of name/ref pairs, so you can export lots in one go:
>   builtin::lexically_export
>     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.

I think this is great.  I think supplying multiple arguments is fine.  The caller can specify what they want and the callee can behave accordingly.
sub import ($self, @names) {
  die "unknown exports" if @names != grep {; defined } @EXPORTS{ @names };

  builtin::lexically_export %EXPORTS{ @names };

> 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.

I think it's fine.  I don't know that we actually have anything that "looks like it would happen at compile time".  We could perhaps issue a warning if it was called when nothing was being compiled?

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