Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
No such thing as a small change
 
PerlMonks  

How many times is Foo::Bar loaded?

by Anonymous Monk
on Apr 09, 2013 at 19:27 UTC ( #1027821=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

If I have package Foo::Bar that is use'd in multiple different classes; when I use these same classes in a single script, how many times does perl compile Foo::Bar? Compiled once for each class, or compiled only once and all classes load it (bring it into their namespace)? My question stems from what Foo::Bar's function is, which creates a lot of overhead when import'd.

Comment on How many times is Foo::Bar loaded?
Select or Download Code
Re: How many times is Foo::Bar loaded?
by LanX (Abbot) on Apr 09, 2013 at 19:32 UTC
    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 file.pm 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)

    update

    corrected import part, thx corion. =)

      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)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1027821]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-04-20 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls