Subject: | "Undefined subroutine in sort" |
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).