Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Detecting if a script uses non-standard module

by Lorand (Beadle)
on Apr 04, 2004 at 17:56 UTC ( [id://342494]=perlquestion: print w/replies, xml ) Need Help??

Lorand has asked for the wisdom of the Perl Monks concerning the following question:

What is the easiest/most elegant way to find out what modules does the base Perl installation have? Especially after you have other modules installed manually (and you don't remember which... :)) I'm asking this, because I would like to know whenever I write a new script if it will run without installing additional modules on any computer with a base Perl 5.8 or later installation.

20040407 Edit by BazB: Changed title from 'Perl Module List'

  • Comment on Detecting if a script uses non-standard module

Replies are listed 'Best First'.
Re: Detecting if a script uses non-standard module
by broquaint (Abbot) on Apr 04, 2004 at 18:07 UTC
    Check out Module::CoreList to see whether a module was part of the core perl release for any given version e.g
    BEGIN { for(@your_list_of_modules) { die "$0: $_ is unavailable in perl$]\n" unless exists $Module::CoreList::version{$]}{$_}; } }
    HTH

    _________
    broquaint

Re: Detecting if a script uses non-standard module
by jZed (Prior) on Apr 04, 2004 at 18:17 UTC
    perldoc perlmodlib will show you the core modules for your currently installed version of perl
      ...except for any modules that depend on external features/libraries/specific platforms that didn't happen to be there the last time it was updated (which should have been done by the pumpking just prior to the perl release).

      IIRC, occasionally things like ODBM_File or IPC::SysV have been left out of perlmodlib.

Re: Detecting if a script uses non-standard module
by davido (Cardinal) on Apr 05, 2004 at 02:36 UTC
    I'd be more interested in a log of what modules I've installed. Perhaps one exists that I haven't found. Sometimes those PPM installations load dependancies faster than I can read them as they scroll by.


    Dave

      All modules are stored in directories contained in the @INC variable. It is not hard to create a perl script to find all modules within those directories. The easiest involves using glob, i.e.:

      foreach my $path (@INC) { my @modules = glob "$path/*.pm"; foreach my $module (@modules) { print "You have module $module installed\n"; } }

      A more elegant solution would involve using File::Find to recursively search the directories, and create the proper names for modules. (For instance, the Net::SMTP module would be called SMTP.pm under the directory Net)


      Want to support the EFF and FSF by buying cool stuff? Click here.
        That doesn't differentiate between which modules were installed as part of the Perl core, and which were installed after the fact. The OP is interested in knowing which modules were bundled with Perl. We already got a pretty good answer; perlmodlib has a mostly up-to-date listing of Perl's core modules. My counter-question was how to determine which modules I've installed that didn't ship with Perl as a core module.

        I guess, to your point, I could use File::Find to resurse Perl's @INC paths, keeping track of the names of all modules found, and then compare that list to the one provided in perlmodlib.


        Dave

      perldoc perllocal gives you a list of the modules installed to the site lib directory. I'm not sure how/whether this works with PPM.

      hth

      --
      I'm Not Just Another Perl Hacker

        perllocal is not updated on module deinstall.
Re: Detecting if a script uses non-standard module
by bart (Canon) on Apr 05, 2004 at 16:18 UTC
    I use a simple rule of thumb: if I can find it under lib, it's a core module, but if under site/lib, where all additional modules get installed by default, it's not...

    But the latter doesn't mean it didn't come with perl — and this is actually your main concern. ActivePerl, likely the distibution for which installing extra modules is seen as problematic (though not actually for technical reasons... ;-)), comes with quite a few extra installed modules, such as XML::Parser, HTML::Parser, and LWP. You surely wouldn't want to miss out on those for no good reason.

    So, the safest is still to check if a standard install comes with them.

    Even so, if a module is worth it, I'd still use it even if it didn't come with perl.

    If anything, it's possible to bundle the additional modules, or the whole install, as a PAR archive.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-24 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found