Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Programatically getting list of dependecies of a CPAN module?

by Plankton (Vicar)
on Jul 02, 2010 at 19:54 UTC ( #847798=perlquestion: print w/replies, xml ) Need Help??
Plankton has asked for the wisdom of the Perl Monks concerning the following question:

Dear Wise Monks,

I am trying to write a script that will list the dependencies of a CPAN Perl module. I already have a script that will print out the tarball that contains the module ...

#!/usr/bin/perl -w use strict; use Data::Dumper; use CPAN; use File::Basename; for my $mod (CPAN::Shell->expand("Module", shift )) { my $url = "" . $mod->{ +'RO'}{'CPAN_FILE'} . "\n"; print "$url"; }
... so if I do ...
$ ./ LWP
... I get ... +.gz
... but I would like to also get a list of dependencies also.

Replies are listed 'Best First'.
Re: Programatically getting list of dependecies of a CPAN module?
by Khen1950fx (Canon) on Jul 02, 2010 at 21:14 UTC
    This'll work.
    #!/usr/bin/perl use strict; use warnings; use CPAN; use CPAN::FindDependencies; use File::Basename; my $mod = shift @ARGV; for $mod (CPAN::Shell->expand("Module", $mod )) { print $mod->cpan_file, "\n"; } my @dependencies = CPAN::FindDependencies::finddeps($mod,); foreach my $dep (@dependencies) { print ' ' x $dep->depth(); print $dep->name().' ('.$dep->distribution().")\n"; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://847798]
Approved by AnomalousMonk
Front-paged by Old_Gray_Bear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2016-10-20 20:48 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (281 votes). Check out past polls.