in reply to Pragma (more) like Java's 'import'?

I'm confused by the answers you have received so far in this thread.

Firstly, if the Module in question is a OO style module, then the only time you need to use the full module name is when you instanciate it:

my $BUGA = Bric::Util::Grp::Asset->new();

from that point on, every method you call upon that instance, you call with the syntax:   $BUGA->method( @args );

Where modules have procedural interfaces (or class methods), then the usual mechanisms for importing individual entrypoints or predefined groups of enterypoints is to use the use Module IMPORT-LIST; syntax (See perlfunc:use.

A breif look at the Bricolage stuff shows that many of the (many, many!) modules support this syntax for importing individual api's or in groups through the use of group selectors ':standard', ':all' and others.

So, in answer to your question: Shouldn't use do this?, I would say the answer is: Yes, and it does:).

Of course, it requires that the modules in question support the syntax, but in the case of Bricolage, it seems that most if not all of them do in as far as it makes sense to.

As for why the Bricolage documentation doesn't exemplify this, choosing to show every call in the full

Module::Submodule::SubSubMod::SubSubSubMod::function()

form (and yes, they really do go that deep!:), I can only speculate at. I did notice that there seems to be an uncommonly large amount of re-use of namespace at different levels of the hierachy, (eg. Asset.pm, Addr.pm, Auth.pm, Contact.pm, Data.pm all appearing twice in the tree, Action.pm appearing 3 times etc.)

Maybe they use the fully qualified names to ensure distinction. Maybe also, if you import :all from two or more of the individual modules you end up with namespace clashes?

If this is the case, then using an auto-import-everything-from-this-module routine is only going to compound matters further as you are likely to import similarly named private routines from the modules too.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

Replies are listed 'Best First'.
Re^2: Pragma (more) like Java's 'import'? (importing and mod_perl)
by Aristotle (Chancellor) on May 12, 2003 at 06:25 UTC
    I have a vague suspicion that they might be avoiding imports due to the memory cost - which is significant in a mod_perl environment.

    Makeshifts last the longest.

      I have a vague suspicion that they might be avoiding imports due to the memory cost - which is significant in a mod_perl environment.

      Importing is aliasing. You're not copying the function, but merely aliasing it. All it costs is one symbol table entry.

      Things are different when autoloading takes place, but it depends on the implementation then.

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

        The aliasing uses memory, and it can really add up in a persistent environment like mod_perl. See this for more specifics.
Re: Re: Pragma (more) like Java's 'import'?
by rinceWind (Monsignor) on May 12, 2003 at 12:32 UTC
    Firstly, if the Module in question is a OO style module, then the only time you need to use the full module name is when you instanciate it
    Not necessarily. The constructor Foo::Bar->new is just one example of a class method as opposed to an object method.

    I'm not familiar with Bricolage, so I don't know if this is true in this case, but there may be several class methods, which are concerned with behaviour of the whole class and all objects in it.

    I've also seen more than one type of constructor used in the same class, e.g. Foo::Bar->lookup('quux.db') which returns a whole list's worth of objects.

    My $0.02

    --rinceWind

      I think I dealt with Class Methods when I said?

      Where modules have procedural interfaces (or class methods), ...


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller