Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: A simple import() for those special moments

by Ctrl-z (Friar)
on Jan 20, 2003 at 17:05 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-16 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found