Update: I've written Module::CheckDeps and checkdeps, so you can use them instead of this script.

Hi everybody. I needed a simple way to check script's dependencies.

Searching on PerlMonks I found two scripts (Check a script's module dependencies and robustly list any Perl code's module dependencies) but I think a better way to achieve that would be using the Module::ExtractUse module, so I wrote my version.

#!/usr/bin/perl # Usage: checkdeps.pl SCRIPT # Check Perl script's dependencies use Module::ExtractUse; use strict; my $script = $ARGV[0] or die "Usage: $0 SCRIPT\n"; open SCRIPT, $script or die "$!\n"; my $code = join "", <SCRIPT>; close SCRIPT; my $p = Module::ExtractUse -> new; $p -> extract_use(\$code); my @used = $p -> array; foreach my $module(@used) { eval "use $module"; next if !$@; print $module."\n"; }

It simply prints every modules not yet installed (one per line) on which the script depends, ready to feed the cpan script.

For example:

$ cpan `perl checkdeps.pl somescript.pl`

Any hints about the code?

Alex's Log - http://alexlog.co.cc

In reply to Check script's dependencies by alexbio

Title:
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, details, 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, summary, 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.