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

Pre-RFC: native lexical importing

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

Using Exporter.pm 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:

https://metacpan.org/pod/Perl6::Export::Attrs
https://metacpan.org/pod/Lexical::Import
https://metacpan.org/pod/Export::Lexical
https://metacpan.org/pod/Exporter::Tiny
https://metacpan.org/pod/namespace::autoclean

Best,
Ovid
-- 
IT consulting, training, specializing in Perl, databases, and agile development
http://www.allaroundtheworld.fr/. 

Buy my book! - http://bit.ly/beginning_perl

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