Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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.

Replies are listed 'Best First'.
Re: How many times is Foo::Bar loaded?
by LanX (Bishop) 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 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. =)

      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1027821]
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2018-07-21 10:18 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (446 votes). Check out past polls.