Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Check the dependencies of modules you want to install

by thomas895 (Chaplain)
on Oct 22, 2012 at 03:50 UTC ( #1000256=CUFP: print w/replies, xml ) Need Help??

Sometimes, when choosing between distributions to install, it helps to see what you need to install, before you actually install it. CPAN Dependencies is a great utility for this, but it's helpful to have something extra: to be able to see what you still need to install. This way, you can predict how long it will take for something to install.
That information is useful to me, because I hate waiting. If there's a distribution that can do the same or similar thing with less dependencies, then I'm more likely to use that.

Today, I decided to make a little solution for that. It's not very elabourate or perfect, but I hope it will be of use to whoever stumbles across it.

#!/usr/bin/perl -w use strict; use warnings; use Config; use LWP::Simple; use XML::LibXML; use Text::Table; #use Data::Dumper qw( Dumper ); use constant CPANDEPS_API_TEMPLATE => 'http://deps.cpantesters.org/?xml=1;module=%s' . ';perl=%s;pureper +l=0;os=%s'; #Get the module name my $wanted_module = shift || die("No module name specified!"); #Get the archname my $archname = "any+OS"; $archname = "Linux" if ( $Config{archname} =~ /linux/ ); $archname = 'Windows+%28Win32%29' if ( $Config{archname} =~ /^MSWin32/ + ); #Get the XML for this module print STDERR "Getting XML...\n"; my $xml_url = sprintf( CPANDEPS_API_TEMPLATE, $wanted_module, $Config{version}, $archname ); my $xml_data = LWP::Simple::get($xml_url); #Place that into LibXML my $doc = XML::LibXML->new->load_xml( { string => $xml_data } ); #Get a list of all the required modules print STDERR "Parsing XML...\n"; my @deps = $doc->getElementsByTagName("dependency"); #print Dumper \@deps; #Try to require() each one my %statuses = ( installed => [], missing => [] ); foreach (@deps) { #Get the module name my $required_module = [ $_->getElementsByTagName("module") ]->[0]->string_value(); #print Dumper [ $_->getElementsByTagName("module") ]->[0]; eval("require $required_module;"); my $col = $@ ? "missing" : "installed"; push( @{ $statuses{$col} }, $required_module ); } #Now, we can show which ones we have and don't have print STDERR "Making table...\n"; my $table = Text::Table->new(qw/ Installed Missing /); #Create lines for the headers $table->load( [ map { "-" x length($_) } qw/ Installed Missing / ] ); #Write table my $i = 0; while (1) { last unless ( $statuses{installed}->[$i] || $statuses{missing}->[$ +i] ); $table->load( [ $statuses{installed}->[$i] || "", $statuses{missing}->[$i] | +| "" ] ); $i++; } print "\n$table";

You need XML::LibXML, LWP::Simple, and Text::Table. Yes, it could have been done with less, but those happened to be the first things that came to mind.

~Thomas~ 
"Excuse me for butting in, but I'm interrupt-driven..."

Replies are listed 'Best First'.
Re: Check the dependencies of modules you want to install
by syphilis (Chancellor) on Oct 23, 2012 at 02:50 UTC
    I hope it will be of use to whoever stumbles across it

    Nice ... it will certainly be of use to me from time to time - and I intend to make use of it.
    I've given it a couple of test runs and it seems fine.

    I try to avoid using the CPAN* modules to handle installations, so having a script like this to tell me up front which modules I need to install is very handy.
    It would be even more handy if it could tell me the order in which I needed to install the missing dependencies, though I suspect this capability might be a little difficult to provide. (Haven't yet had time to investigate that aspect.)

    Cheers,
    Rob

      It would be even more handy if it could tell me the order in which I needed to install the missing dependencies
      That would be handy, agreed, but usually when using cpan or cpanp(not sure about cpanm, never used it), the dependencies are automatically installed for you. That's handy, until one distribution in the chain of many decides to fail on a test or make, in which case you get to start over again(for the most part).

      I don't think I can do it with just CPANDeps' XML, I would likely have to poll many sources to get that information.

      ~Thomas~ 
      "Excuse me for butting in, but I'm interrupt-driven..."
        I don't think I can do it with just CPANDeps' XML, I would likely have to poll many sources to get that information.

        Does the "depth" field tell us anything useful in regard to a module's position in the dependency chain ?

        I certainly wouldn't advocate pulling in more sources, as the nice feature of this script is the promptness with which it provides the information.
        The only other thing it fails to detect is the case where the version of the dependency that is already installed is not sufficiently recent. (To remedy this would also require significant additional overhead.)
        Anyway, like I said, I'll be making good use of it as is ;-)

        I opened up one of the XML files in my browser, and found this near the beginning of the file:
        This is an experimental XML interface. It's structure and location may change. If you want them to change, please ask. Please try to avoid kicking the shit out of my server, it's only little and doesn't like being bullied.
        So there's a couple of things of which we need to be mindful.

        Cheers,
        Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://1000256]
Approved by Athanasius
help
Chatterbox?
[stevieb]: it's Quebec... they do weird stuff there :) In the mountains, it is *mandatory* for trucks to use tire chains. Many passenger vehicles do as well (but it's not mandatory for them)
[perldigious]: That stuff can hit fast... like what we just got where I'm at. Saw a few people who had slid OUT of the roundabout I have to drive through to get to work, not used to the ice yet, take awhile to get the hang of it again and make vehicle adjustments.
[stevieb]: man, when the roads are glare ice, I don't even bother going to work or out... unless I absolutely have to, or was already out in the first place
[choroba]: Tire chains are mandatory here in mountains, and the only unprepared each year are gritters
[stevieb]: I have a 3 day winter survival kit in my vehicle in the event I get snowed in in the mountains (which has happened before due to avalanches closing the roads (and once in the summer due to a massive forest fire that trapped us
[perldigious]: a handful of people in my work area did not make it, but I live pretty close and it's flat the whole way, so I didn't have any trouble. The roundabout is the worst thing I have to negotiate.
[thezip]: G'day all!
[perldigious]: Well, that and dodging the people who forget how ice works right away. :-)
[stevieb]: hey, thezip
[perldigious]: I don't miss having to drive up and down in elevation on roads that are iced over, I white knuckled gripping the steering wheel every time I had to where I used to live.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2016-12-06 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.