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

Pre-RFC: native lexical importing

Thread Next
Ovid via perl5-porters
February 12, 2022 09:36
Pre-RFC: native lexical importing
Message ID:
Some people expressed interest in the :export functionality of the module proposal. Thus, another pre-RFC.

Using or writing your own import() sub is very clumsy, but very common. This should be native to Perl.

The idea is to provide exporting via an `:export` attribute:

    package Foo {
        sub bar :export {...} # @EXPORT_OK
        sub baz :export(:strings) %EXPORT_TAGS
        sub quux :export(:ALWAYS) {...} # @EXPORT
        sub whee {...} # not exported

These exports are set via attributes, they do *not* require the import() sub to be called, and they are lexical.

Open questions.

1. How would one would handle delayed importing? `Foo->import('bar');`

2. Allow renaming of imported functions?

3. "Lexical importing" means "callable until end of enclosing block unless shadowed", but does that also mean that it's not in the symbol table? (I would assume so)

Related prior art on the CPAN:

IT consulting, training, specializing in Perl, databases, and agile development 

Buy my book! -

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