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

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.

Replies are listed 'Best First'.
Re^3: how NOT to import exported subs/variables from a module?
by adrianh (Chancellor) on May 31, 2006 at 12:42 UTC
    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.

        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.

        Yup. Although, personally, I think that use with an explicitly empty import list is a clear winner on the readability front because of its lack of ambiguity.

        I would tend to write as I described above to stand out better -- or perhaps write "use Module qw()" for a similarly distinctive effect.

        We'll just have to agree to differ I guess. I don't really see any difference in readability between using qw() or not - although I can see an argument for using qw() to make adding/removing items from the import list easier.