Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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?


Comment on Re: A simple import() for those special moments
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-07-29 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls