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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Check script's dependencies
by runrig (Abbot) on May 25, 2010 at 17:51 UTC | |
by alexbio (Monk) on May 25, 2010 at 18:01 UTC | |
Re: Check script's dependencies
by Khen1950fx (Canon) on May 27, 2010 at 06:26 UTC | |
by alexbio (Monk) on May 27, 2010 at 16:47 UTC | |
Re: Check script's dependencies
by Anonymous Monk on Jun 15, 2010 at 18:02 UTC |
Back to
Cool Uses for Perl