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:
Chad Granum
Date:
December 18, 2015 04:55
Subject:
Re: Proposal: Add {-as => 'new_name'} feature to Exporter.pm
Message ID:
CAJFr3ks-iFYY9vnOtvdvLa_U=js3iaR5_fcLqBFBLoawd8boKg@mail.gmail.com
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. To make it go
away you have to delete the entire stash slot and put back the stuff you do
not want to get rid of. Also the rename functionality is usually for cases
where there is a conflict, so if you import both and rename after you have
to be careful of operation order.

That said I did write this just last night:
https://metacpan.org/pod/release/EXODIST/Import-Into-As-0.000002/lib/Import/Into/As.pm

Take a look at the code to see how awful it actually is. On the other hand
doing it as an argument to import() provided by exporters is very simple.

-Chad

On Thu, Dec 17, 2015 at 7:50 PM, Zefram <zefram@fysh.org> wrote:

> Chad Granum wrote:
> >Several modern export tools such as Sub::Exporter and Exporter::Declare
> >make it possible to rename subs that you import.
>
> Appealing though such features are, the exporting side is the wrong place
> to do it, precisely because it would need to go into every exporter.
> Better to keep the exporter's obligations minimal, and address this
> on the importing side.  The facility can be written once to be applied
> regardless of exporter type, and it only need be invoked by importing
> modules that actually want to use the facility.
>
> -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