Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: How many times is Foo::Bar loaded?

by LanX (Chancellor)
on Apr 09, 2013 at 19:32 UTC ( #1027822=note: print w/replies, xml ) Need Help??

in reply to How many times is Foo::Bar loaded?

A use is a complicated require which is a complicated "do file" which is a complicated eval.

As you easily see from the documentation every used is only evaled once and import() is only called once is called each time to drag the listed symbols into the current namespace.

Cheers Rolf

( addicted to the Perl Programming Language)


corrected import part, thx corion. =)

Replies are listed 'Best First'.
Re^2: How many times is Foo::Bar loaded?
by Corion (Pope) on Apr 09, 2013 at 19:33 UTC

    Actually, ->import() is called for every use statement. The eval part only happens once.

      Off course, makes sense since the import-list can change...

      Cheers Rolf

      ( addicted to the Perl Programming Language)

        Not just because the import list can change... The more important reason for doing the ->import() step every time is that a Perl program can be spread across many files (modules or otherwise) and those files can define many namespaces, each of which may need to import symbols from the same module.

        If ->import() was only called the first time, then only the first namespace to use the module would import its symbols and any other namespaces which expected them to be available would fail. And fail in very-difficult-to-debug ways, since the failure would be dependent on which files are loaded and in what order.

        Thank you all, that was very helpful

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2016-10-27 02:17 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (352 votes). Check out past polls.