in reply to Which "use" statements in a module do "bubble up" to the callers? [SOLVED]

A key thing to know about Perl is that the use directive is, shall we say, overloaded. Sometimes it is a file-inclusion directive similar to require, and sometimes it is a pragma ... an instruction to the compiler ... and there is no consistency among the pragmas. So it goes. Some language-implementors chose to use different keywords for the different cases, but long ago Perl did not. Even third-party packages can do it, as with the use Moose and no Moose directives that can fill source-code where Moose is being employed. You can't make generalizations about use. You have to know from context what each instance means.
  • Comment on Re: Which "use" statements in a module do "bubble up" to the callers? [SOLVED]

Replies are listed 'Best First'.
Re^2: Which "use" statements in a module do "bubble up" to the callers? [SOLVED]
by Anonymous Monk on Sep 01, 2017 at 14:34 UTC
    use is require followed by import, no more and no less. import is defined by the module in question, and can do whatever it wants. Normally, it adds stuff to the caller's symbol table, but it doesn't have to.
      use is require followed by import, no more and no less.

      I agree that the parent could be worded better, but if we're being nitpicky, that's also not quite right. use Module VERSION LIST (where both VERSION and LIST are optional) is equivalent to:

      BEGIN {
        require Module;
        Module->VERSION( VERSION );  # if VERSION was specified
        Module->import( LIST );      # *except* when LIST is "()"
      }
      

      And use VERSION; requires a minimum version of Perl. That's all use does, and whether the Module is a prgama, regular module, or whatever else, is up to that module and its import, not use. Update: Well now I need to nitpick myself - use VERSION; also enables the feature bundle for that version and strict if the version is 5.12 or greater. Also, it should be noted that if Module doesn't have a sub import, no error is raised.

        pee-ay yeh-zoo doh-mee-nay *thunk* doh-nah eh-ees re-kwee-em *thunk*