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

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

Thread Previous | Thread Next
From:
Zefram
Date:
December 18, 2015 05:22
Subject:
Re: Proposal: Add {-as => 'new_name'} feature to Exporter.pm
Message ID:
20151218052241.GK7818@fysh.org
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.

-zefram

Thread Previous | 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