develooper Front page | perl.perl5.porters | Postings from December 2015

Re: Proposal: Add {-as => 'new_name'} feature to

Thread Previous | Thread Next
December 18, 2015 05:22
Re: Proposal: Add {-as => 'new_name'} feature to
Message ID:
Chad Granum wrote:
>The problem is that it is very hard to do on the importing side. Once a sub
>is entered into your namespace it is hard to undefine it.

That would be a silly way to do it.  The sensible way is to first import
into a scratch package (via the exporter, using standard names), then
the import-side code can import from the scratch package into the caller
package under a different name.  There's no conflict, and you don't undo
anything (except for deleting the entire scratch package).  It's not hard.
See Lexical::Import for how the scratch package thing operates.

It's a bit inconvenient that the standard API for object exporting
involves mutation of a package, and a package specified implicitly via
caller() at that.  But it's a workable API, and its adoption is almost
totally universal.  We should embrace the opportunity to use it to plug
composable components together.


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