Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

calling module with empty import

by jesuashok (Curate)
on May 17, 2007 at 07:09 UTC ( #615942=perlquestion: print w/ replies, xml ) Need Help??
jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

All Perl Pisthus,

use Module (); # Imports Nothing
What is the realtime use of the above code ? Calling a module forcing not to import anything ?

Comment on calling module with empty import
Download Code
Re: calling module with empty import
by Zaxo (Archbishop) on May 17, 2007 at 07:20 UTC

    Yes, that prevents default imports.

    After Compline,
    Zaxo

Re: calling module with empty import
by gaal (Parson) on May 17, 2007 at 07:25 UTC
    Export/import happens in Perl by convention: "use Module" calls Module::import, which typically does some initialization and places symbols in the caller's namespace.

    It's recommended that module authors not export things by default, but some modules don't follow that recommendation. For example, YAML exports Dump and Load. What if your code already defines subs with those names? You still want to be able to use YAML's functions, e.g. by saying YAML::Dump($obj), but you don't want the default import. So you "import" (), and YAML::import never gets called. Note that if YAML.pm had had some important initialization it only did in its import sub, that would be missed.

Re: calling module with empty import
by ysth (Canon) on May 17, 2007 at 08:14 UTC
    More declaring that you aren't interested in anything that might be exported. It's a useful piece of auto-documentation even when the used module doesn't even have an import routine.
Re: calling module with empty import
by perrin (Chancellor) on May 17, 2007 at 13:53 UTC
    As others said, it prevents importing of default symbols. It's common to see this in long-running daemon environments like mod_perl and FastCGI, since it reduces the memory footprint of the process. Every imported symbol costs some memory.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://615942]
Approved by bingos
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-08-21 17:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (138 votes), past polls