I was hoping for Module :: ScanDeps , which provides the scandeps.pl command-line utility , but, unfortunately, Module::ScanDeps does not seem to be intended for this specific purpose, because scandeps.pl ignores missing modules or (with -c or -x ) screams when the script uses a module that is not installed.
Here is a quick'n'dirty Perl script that tries to execute the script with do until it succeeds
#!/usr/bin/perl use strict; use warnings; use Term::Prompt; my ($script) = @ARGV; die "Provide script file name on the command line\n" unless defined $script; until ( do $script ) { my $ex = $@ ; if ( my ($file) = $ex =~ /^Can't locate (.+?) in/ ) { my $module = $file; $module =~ s/\.(\w+)$//; $module = join('::', split '/', $module); print "Attempting to install '$module' via cpan\n"; system(cpan => $module); last unless prompt(y => 'Try Again?', '', 'n'); } else { die $ex; } }
If you do not want the script to run, you can run perl -c $script , write stderr output of this, and analyze the missing module messages and call cpan for each such module found before the perl -c $script outputs "Syntax OK". This gives you a cleaner cycle. I will look at this later.
You can skip dependencies loaded at runtime using this technique.
Sinan ΓnΓΌr
source share