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:
Ricardo Signes
Date:
December 22, 2015 17:02
Subject:
Re: Proposal: Add {-as => 'new_name'} feature to Exporter.pm
Message ID:
20151222170224.GA9118@cancer.codesimply.com
* Chad Granum <exodist7@gmail.com> [2015-12-22T11:27:11]
> The way I am handling groups is this: First the import list is scanned for
> the hashes, which are put into a hash where the symbol is the key. Then
> Exporter.pm does its thing to expand @imports (include symbols in tags or
> pattern matches). Then Exporter.pm iterates over the imports to export
> them, for each one it looks for the symbol in the hash to find the
> {-as=>...} hash associated with the symbol, if none is found exporting is
> normal, if one is found it exports it under the new name. This allows
> someone to specify a group, and rename select symbols within the group by
> specifying them again with the hash.

If you're going to import a group with ten elements, you're going to want
prefix/suffix.  It is madness to have to write:

  use Math::Slow
    add => { -as => "slow_add" },
    mul => { -as => "slow_mul" },
    div => { -as => "slow_div" },
    mns => { -as => "slow_mns" },
    mod => { -as => "slow_mod" };

instead of

  use Math:Slow ':basics' => { -prefix => "slow_" };

Maybe sometimes you'll want a whole group, but to rename things one by one.  In
this case, maybe:

  use Math::Slow ':basics' => { -rename => { 'add' => 'slow_add' } };

What you seem to have suggested is:

  use Math::Slow ':basics',
    add => { -as  => 'slow_add' };

...which, to me, is needlessly ambiguous.  Does this give me two copies of
&add, one renamed and one not?  If not, how do I get two copies if I want it?
Do I have to call import multiple times?

-- 
rjbs

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