Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Sub-Exporter CPAN distribution.

Report information
The Basics
Id: 80234
Status: rejected
Priority: 0/
Queue: Sub-Exporter

People
Owner: Nobody in particular
Requestors: DAMI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: add support for "!"
Sub::Exporter lacks the "negative" feature of Exporter : use Some;:Module qw/:all !foo/; which would import all exported functions from Some::Module _except_ function "foo". This is quite useful if the client wants to rewrite its own version of "foo" (better than "no warnings 'redefine'"). I recently converted my module Data::Domain to use Sub::Exporter instead of good old Exporter, but now I discover this was not a fully compatible replacement, so I'm having problems with some clients of Data::Domain which were using this feature.
On 2012-10-16 23:15:48, DAMI wrote: Show quoted text
> Sub::Exporter lacks the "negative" feature of Exporter : > > use Some;:Module qw/:all !foo/;
Because each non-reference entry in the args to ->import is treated atomically, these semantics can't be quite supported. More plausible would be: use Some::Module ':all' => { -exclude => 'foo' }; ...but that won't get you what you want, which is full back compat. On that front, there are a number of other features missing as well. Sub::Exporter is not a drop-in. What you *could* do, however, is write a collector for INIT that would pick an alternate installer, detect the case of "group name followed by bang-name" and then mark those names for non- installation. It should actually be pretty simple, once you see how the pieces fit together.
Subject: Re: [rt.cpan.org #80234] add support for "!"
Date: Sat, 20 Oct 2012 03:23:25 +0200
To: bug-Sub-Exporter [...] rt.cpan.org
From: laurent dami <laurent.dami [...] free.fr>
Le 17.10.2012 05:19, Ricardo Signes via RT a écrit : Show quoted text
> What you *could* do, however, is write a collector for INIT that would > pick an alternate installer, detect the case of "group name followed > by bang-name" and then mark those names for non- installation. It > should actually be pretty simple, once you see how the pieces fit > together.
Please find a proposal to implement support for bang-names directly in _do_import; that's the place where we have a global view on the export list, so it seems easier to do it there. https://github.com/rjbs/sub-exporter/pull/5
The INIT collector also has this information. I suggest implementing this as an extension. The args to a Sub::Exporter-built import method are an optlist, and should remain one. -- rjbs
Subject: Re: [rt.cpan.org #80234] add support for "!"
Date: Sat, 20 Oct 2012 04:48:08 +0200
To: bug-Sub-Exporter [...] rt.cpan.org
From: laurent dami <laurent.dami [...] free.fr>
Le 17.10.2012 05:19, Ricardo Signes via RT a écrit : Show quoted text
> What you *could* do, however, is write a collector for INIT that would > pick an alternate installer, detect the case of "group name followed > by bang-name" and then mark those names for non- installation. It > should actually be pretty simple, once you see how the pieces fit > together.
OK, I found a solution following your advice (see code below). It wasn't actually that simple : I spent some time in the debugger to understand a) that datastructures are not the same between "import_args" (an array of arrayrefs to pairs) and "to_import" (a flat array of pairs) b) that the alternate installer must be given in the initial config; by the time we reach INIT, it's too late to add an installer into %$config, because build_exporter() has already created its own copy in "my $installer" (line 732). So I must always inject a custom installer, and communicate with INIT through a global variable :-( Anyway, I reached what I wanted; thanks for the tips. For info, here is the code : use Sub::Exporter -setup => { exports => ... groups => ... collectors => { INIT => \&_init }, installer => \&_installer, }; # customizing Sub::Exporter to support "bang-syntax" (excluding symbols) { my @dont_export; sub _init { my ($collection, $context) = @_; my $args = $context->{import_args}; my ($exclude, $regular_args) = part {!ref $_->[0] && $_->[0] =~ /^!/ ? 0 : 1} @$args; @$args = @$regular_args; @dont_export = map {substr($_->[0], 1)} @$exclude; } sub _installer { my ($arg, $to_export) = @_; my %export_hash = @$to_export; delete @export_hash{@dont_export}; Sub::Exporter::default_installer($arg, [%export_hash]); } }
Cool, thanks for letting me know you got it goin'! -- rjbs