Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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 ?

Replies are listed 'Best First'.
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 had had some important initialization it only did in its import sub, that would be missed.

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

    Yes, that prevents default imports.

    After Compline,

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://615942]
Approved by bingos
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2018-06-24 01:37 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.