Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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?

In reply to Re: A simple import() for those special moments by Ctrl-z
in thread A simple import() for those special moments by Aristotle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-19 04:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found