Skip to content

Instantly share code, notes, and snippets.

@walf443
Created February 20, 2013 14:01
Show Gist options
  • Save walf443/4995732 to your computer and use it in GitHub Desktop.
Save walf443/4995732 to your computer and use it in GitHub Desktop.
trying cpanm if got "Can't localte xxx.pm"
use strict;
use warnings;
use Capture::Tiny ':all';
sub main {
my @args = @_;
my $stderr = do_try(@args);
while (1) {
if ( $stderr && $stderr =~ /Can't locate (.+?)\.pm / ) {
my $file = $1;
my $module = join("::", split(qr{/}, $file));
do_log("trying cpanm $module");
system("cpanm " . $module);
} else {
do_log("finished!!");
exit;
}
}
}
sub do_try {
my @args = @_;
my $cmd = join(" ", @args);
my ($stdout, $stderr, $exit) = capture {
system($cmd);
};
return $stderr;
}
sub do_log {
my ($message, ) = @_;
print "$0: $message\n";
}
main(@ARGV);
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment