Created
February 20, 2013 14:01
-
-
Save walf443/4995732 to your computer and use it in GitHub Desktop.
trying cpanm if got "Can't localte xxx.pm"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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