The motivation is that I like to ship CPAN modules with the fewest dependencies possible for the sake of minimalism. A common desire when authoring the module is to use functions from other packages, but not litter my method namespace with those functions. The "best practice" way to do that is:
but namespace::clean is not a core module. The most minimal of all options is to just reference the function by its full name:use Scalar::Util 'looks_like_number'; use namespace::clean; ... looks_like_number($x) ...
but that is tedious and makes me unhappy while writing the code.use Scalar::Util (); ... Scalar::Util::looks_like_number($x) ...
I have the option of lexical subs:
but I'm introducing a tiny bit of runtime inefficiency for the sake of more pleasant authoring.use v5.20; use experimental 'lexical_subs'; use Scalar::Util (); my sub looks_like_number { &Scalar::Util::looks_like_number } ... looks_like_number($x) ...
What I really want is:
but this gives me "Illegal declaration of subroutine looks_like_number".use v5.20; use experimental 'lexical_subs'; use Scalar::Util (); my sub looks_like_number = \&Scalar::Util::looks_like_number; ... looks_like_number($x) ...
Is there any way in pure-perl with only core modules to achieve a lexical sub which *is* the same coderef as the fully qualified global name?
In reply to Pure perl lexical sub import by NERDVANA
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |