http://www.perlmonks.org?node_id=698698

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

Is there a "good" way to find out what modules another module depends upon?

I want to build a machine with most of the perl libraries as another machine. I don't want to just use autobundle, because I don't want to install everything. I figure the best way to do this is to find all the modules aren't depended upon, IE the root of the dependency tree. In order to do that, I figure I'll have to go through all my installed modules and find out what they use/require and then take the results and turn them upside down. Once I have this list, it will be pretty easy to see what's junk and what's important.

I'd rather not parse the text of all the modules on my computer, so that's what I mean by "good", but if that's what I have to do, then so be it.

Thanks!
--Pileofrogs

Replies are listed 'Best First'.
Re: Installed Module Dependencies?
by almut (Canon) on Jul 18, 2008 at 18:56 UTC

    Module::ScanDeps might help... (it's for example used by PAR)

    Update: but note that when you're dealing with XS modules, Module::ScanDeps won't determine secondary dependencies of shared object files (at least I wouldn't know how...).

    For example, lets say you're trying to track the dependencies of the module GD, which has architecture-specific parts. In this case, Module::ScanDeps will only tell you about the immediate shared object file GD.so that's loaded by Dynaloader.  However, GD.so in turn depends on a multitude of other shared libs, like libgd, libpng, libjpeg, libfreetype, libfontconfig, libexpat, etc., without which the GD.so shared object will not work...  (Some of those libs may come with the default OS installation, but typically not all of them... Also, you'd have to make sure that versions are matching.)

    In other words, if you want to get such a module working on another machine, you'd have to take care of determining/packaging those dependencies yourself (with the help of the appropriate system tool, like ldd on Linux).

Re: Installed Module Dependencies?
by oko1 (Deacon) on Jul 18, 2008 at 19:09 UTC

    Take a look at Module::ScanDeps. It comes with a script called 'scandeps.pl' that should do what you're looking for.

    (Disclaimer: I have not tested this thoroughly or used it in a live-fire scenario; I tracked it down by recalling that PAR/pp has this functionality, reading the docs, and trying a few simple tests.)

    
    -- 
    Human history becomes more and more a race between education and catastrophe. -- HG Wells
    
Re: Installed Module Dependencies?
by Khen1950fx (Canon) on Jul 19, 2008 at 19:35 UTC
    Here's a little script that I use for finding dependencies:

    #!/usr/bin/perl use strict; use warnings; use ExtUtils::MakeMaker; use CPAN::FindDependencies; my $mod = prompt("Enter module name: "); my @dependencies = CPAN::FindDependencies::finddeps($mod); foreach my $dep (@dependencies) { print ' ' x $dep->depth(); print $dep->name().' ('.$dep->distribution().")\n" }

    It can be adjusted to fit your needs.

Re: Installed Module Dependencies?
by trwww (Priest) on Jul 19, 2008 at 01:02 UTC

    Hello,

    I didn't comb though your requirements, so this might be simple enough for you, but then again might not be.

    I've used the following when I need a list of modules that are loaded in to my application:

    perl -Ilib -MMyApp -e 'print map "$_\n", sort keys %INC'

    trwww

Re: Installed Module Dependencies?
by DrHyde (Prior) on Jul 21, 2008 at 10:44 UTC