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

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

Thread Previous | Thread Next
Kent Fredric
December 22, 2015 10:04
Re: Proposal: Add {-as => 'new_name'} feature to
Message ID:
On 22 December 2015 at 13:12, Ricardo Signes <> wrote:
> tl;dr -- I think adding this feature as described is the right choice.  We'll
> probably want to make a couple little tweaks and make sure we've got good test
> coverage.
> 2.  Is the { -as => "newname" } implementation the right one?
>     I'm not really sold.  I think the hashref is okay.  We can validate that
>     the only entry in it is "-as", to prevent crazy mistakes.
>     Someone mentioned that this doesn't support groups. This is correct.  In
>     Sub::Exporter, groups can take a similar argument, which can contain
>     -prefix or -suffix.  We could also provide that.
>       use Pies ':savory' => { -prefix => 'yummy_' };
>       use Cake::Const "/^CK_/" => { -suffix => '_CONST' };
>     I'm not too worried about making this look like anything else that uses it.
>     That's a nice little benefit, but there will be other differences, so
>     people will want to know what's under the hood.  I just want it to be easy
>     to skim and understand, and this passes that test.

While we're comparing features Sub::Exporter has but Exporter lacks,
lets remember that very useful ability to just pass a string of the
intended target packages name to `import()` and have it just work:\%28.{0%2C200}into

This is much much nicer than needing to dick around with `eval`.

Given such a feature is clearly in high enough demand that we may also
want it some day, and that it might also change the import()
interface, it makes sense to at least consider how we'd have both
features available in some future.

Looking in the internals shows me that there already *is* some glue in
Exporter to make this possible, but its currently blocked by all the
user facing API's refusing to communicate an arbitrary target:


But it looks like you can replace:

    eval "package Foo; Bar->import(@args)"



But it turns out there's almost nobody using that syntax on CPAN:

But one of the 2 cases there that actually calls that is really interesting....


Yeah. Prior Art of exactly the sort of thing we want to be doing, with
some superficial implementation similarities

Its kinda gross because it requires temporarily monkey patching
Exporter to give the new syntax, and then hoping you didn't break
anything you didn't mean to tweak, and then putting the burden on you
to unbreak it when you're done.


But still interesting as research material.



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