Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Comment on

( #3333=superdoc: 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 => ';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.

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

In reply to Check the dependencies of modules you want to install by thomas895

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (4)
    As of 2018-01-17 19:10 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (203 votes). Check out past polls.