Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Check the dependencies of modules you want to install

by thomas895 (Hermit)
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..."

Comment on Check the dependencies of modules you want to install
Download Code
Re: Check the dependencies of modules you want to install
by syphilis (Canon) 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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-12-19 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (79 votes), past polls