Skip Menu |
 

This queue is for tickets about the namespace-clean CPAN distribution.

Report information
The Basics
Id: 101247
Status: resolved
Priority: 0/
Queue: namespace-clean

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

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



Subject: "Undefined subroutine in sort"
Download (untitled) / with headers
text/plain 659b
The following does not work : use My::Comparison::Module qw/cmp_func/; use namespace::clean -except => 'meta'; ... my @sorted = sort cmp_func @data; yielding error message "Undefined subroutine in sort". Apparently the indirect call to cmp_func through sort() only gets resolved at runtime, and since namespace::clean has already removed it from the symbol table, we get an error. I'm not sure if this can be solved at all, since it has to do with the treatment of sort() by the Perl compiler. One workaround of course is to say -except [qw/meta cmp_func/]. Another workaround is sort {cmp_func($a, $b)} @data (a bit silly, but it works).
Download (untitled) / with headers
text/plain 923b
On 2015-01-02 03:57:44, DAMI wrote: Show quoted text
> The following does not work : > > use My::Comparison::Module qw/cmp_func/; > use namespace::clean -except => 'meta'; > ... > my @sorted = sort cmp_func @data; > > yielding error message "Undefined subroutine in sort". > > Apparently the indirect call to cmp_func through sort() only gets > resolved at runtime, and since namespace::clean has already removed it > from the symbol table, we get an error. > > I'm not sure if this can be solved at all, since it has to do with the > treatment of sort() by the Perl compiler. > > One workaround of course is to say -except [qw/meta cmp_func/]. > Another workaround is > > sort {cmp_func($a, $b)} @data > > (a bit silly, but it works).
Or perhaps: my $cmp_func = \&cmp_func; # outside of a sub block, so it gets executed when the module is loaded sub foo { ... my @sorted = sort $cmp_func @data; }
Download (untitled) / with headers
text/plain 361b
On Fri Jan 02 12:57:44 2015, DAMI wrote: Show quoted text
> > I'm not sure if this can be solved at all, since it has to do with the > treatment of sort() by the Perl compiler. >
Correct. I documented this explicitly and added Ether's workaround as an example: https://metacpan.org/pod/release/RIBASUSHI/namespace-clean-0.26/lib/namespace/clean.pm#Late-binding-caveat Cheers


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.