http://www.perlmonks.org?node_id=228398


in reply to A simple import() for those special moments

Interesting. I had an old piece of code something similar, that I used for miscellaneous function libraries.
It worked on the surface, but as ihb pointed out, theres probably subtleties i have not understood or accounted for - Globs are pretty scary!

package Exporter::Lite; no strict 'refs'; sub import { my $namespace = shift; my $caller = caller(); if ($namespace eq __PACKAGE__) { # ie use Exporter::Lite; # put import symbol in callers table, and ignore any args *{ "$caller\::import" } = *{__PACKAGE__."\::import"}; return; } else { # ok, we have a "use myModule qw(blah foo);" foreach(@_) { *{ "$caller\::$_" } = *{"$namespace\::$_"}; } } } 1;
edit: my way definitely suffers from the same clobbering problem as mentioned in Aristotle's last post. Just sneaked in before me.
But I wonder, if your are explicitly importing a symbol, would you be likely to name your own variables the same as what had been imported?