Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This is more of a theoretical danger though. Yes, it can leak and we both know you shouldn't actually do this. It's not very safe to use a pattern to decide what to export to begin with. Stuff like this should be done explicitly, so you know what you have and what you get, etc.

But when is this leaking a problem? Sure, X gets an extra subroutine. But what difference does that make? When would X be calling this &foo, if it doesn't exist? Sure, there's the AUTOLOAD issue, but we have to believe that whoever uses the technique in the root node is knowing what he's doing and knows not to use AUTOLOAD since he implicitly aliases symbols. Symbols, I repeat.

"But what if X has its own &foo", I hear you (or someone else) say. If defined before the import, no problem. That can be detected and issue a warning. (A glob overwrite warning.) If defined after the import, well, then you get a debugging hell--if you're not using warnings. Because a "Subroutine %s redefined" warnings will be issue. If not using warnings, well, I don't want to think about it. The package will change the exporting module's &foo and that will in its turn change all &foo's out there that has been imported. (It doesn't actually do this chain. They're all just one and the same.)

To put this in context of your code in the root node: The importing module shouldn't have any symbol names what-so-ever that matches the pattern that the exporting module uses. (Of course documented in the exporting module.) Neither module should be using AUTOLOAD, since symbols are aliased implicitly. The &foo issue above can be generalized: all importing modules will share the same symbol, meaning that if one importing module modifies the symbol then all importing modules will also get the symbol modified.

This all might seem scary as hell, and yeah, it can be. But this is also a quick'n'dirty hack. Since when is "arbitrary" imports considered OK by the purists anyway?

ihb

PS. I'm not actually arguing with you, even though it may sound like it. I'm just elaborating on the subject.


In reply to Re: Re^4: A simple import() for those special moments by ihb
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 musing on the Monastery: (2)
As of 2024-04-20 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found