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 14:59
Subject:
Re: Proposal: Add {-as => 'new_name'} feature to Exporter.pm
Message ID:
CAJFr3ksW-V_uoC-btBZ8ZavpyGkUojoRFiG6G3Gu0kLFK_af+w@mail.gmail.com
>
>
> How about passing an array reference of source / destination name pairs
> instead ? Like :
>
>     use Foo [ name1 => 'name2', name3 => 'name4', name6 => 'name7' ],
>             'name5';
>
> It seems shorter and easier to validate (unless that's already used by
> Exporter.pm, of course).
>
>
> Vincent
>

1) I think consistency may be more important here. The syntax I am
introducing matches Sub::Exporter and Exporter::Declare.

2) I used syntax exactly as you are proposing for an exporter internal to
something else a while back. You would be surprised how many people argues
that it should be [dest => source] instead of [source => dest], and how
many people were confused. Ultimately we agreed that '=>' would be read as
'as', at which point someone reminded me that Sub::Exporter uses {-as =>
'xxx'} which removed any confusion or doubt as to what order things were
in, despite the extra characters it added for typing.

3) The name => { ... } syntax is extendable in the future, we can add other
keys into it to have other effects on individual subs. the [old => new]
syntax effectively limits arrayrefs to being used for renaming, and it
cannot be easily extended.

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