Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: A simple import() for those special moments

by Ctrl-z (Friar)
on Jan 20, 2003 at 17:05 UTC ( #228398=note: print w/replies, xml ) Need Help??

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?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://228398]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (13)
As of 2019-10-18 11:34 GMT
Find Nodes?
    Voting Booth?