Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: how NOT to import exported subs/variables from a module?

by Sandy (Curate)
on May 30, 2006 at 19:36 UTC ( [id://552611]=note: print w/replies, xml ) Need Help??


in reply to how NOT to import exported subs/variables from a module?

From the docs...

perldoc -f use ... If you do not want to call the package's "import" method (for instance, to stop your namespace from being altered), explicitly supply the empty list: use Module ();
This should do it.

Sandy

Replies are listed 'Best First'.
Re^2: how NOT to import exported subs/variables from a module?
by xdg (Monsignor) on May 30, 2006 at 20:12 UTC

    The next two lines of that documentation are:

    That is exactly equivalent to BEGIN { require Module }

    So unless you need the compile time action from BEGIN, plain require works also. It's only one extra character over use with an empty list and I find it stands out better visually as being a module load without import side-effects.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      So unless you need the compile time action from BEGIN, plain require works also. It's only one extra character over use with an empty list and I find it stands out better visually as being a module load without import side-effects.

      That's interesting. I would far prefer use Module () since it explicitly says to me "I am deliberately not importing anything' where require Module might be saying any of:

      • I don't want to run at compile time
      • I don't want to run import() yet
      • I don't want to run import() at all (for whatever reason)
      • I don't want to run import() because I don't want to add any subs/variables to my namespace
        That's interesting. I would far prefer use Module () since it explicitly says to me "I am deliberately not importing anything' where require Module might be saying any of:

        Interesting counter-point. It sounds like a difference either in how we read code or in how we prefer to optimize our code for readability. (Those are similar, but subtly different.)

        I would tend to not read anything into require other than its literal meaning and reserve judgement about intent until I see it used later (e.g. import or a function/method call). I would tend to write as I described above to stand out better -- or perhaps write "use Module qw()" for a similarly distinctive effect.

        -xdg

        Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re^2: how NOT to import exported subs/variables from a module?
by jfroebe (Parson) on May 30, 2006 at 19:40 UTC

    DOH!

    You know, I could swear that was just added to my perldoc in the last 10 seconds by elves or something... Thanks!! :)

    Jason L. Froebe

    Team Sybase member

    No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

      IMHO, that sounds more like something the wee folk would do... ;-)

      planetscape

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-25 05:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found