Created
February 19, 2010 10:19
-
-
Save gfx/308611 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| diff --git a/cpanm b/cpanm | |
| index 4b4e71c..366958f 100755 | |
| --- a/cpanm | |
| +++ b/cpanm | |
| @@ -4,18 +4,18 @@ use Config; | |
| use File::Basename qw(basename); | |
| use Fatal qw(chdir); | |
| use Parse::CPAN::Meta; | |
| +use File::Spec; | |
| sub get($); | |
| sub mirror($$); | |
| sub untar; | |
| +sub which; | |
| -my $wget = `/usr/bin/which wget`; | |
| -chomp $wget; | |
| if (eval { require LWP::Simple }) { | |
| *get = \&LWP::Simple::get; | |
| *mirror = \&LWP::Simple::mirror; | |
| -} elsif ($wget && -x $wget) { | |
| +} elsif (my $wget = which 'wget') { | |
| *get = sub ($) { | |
| my $uri = shift; | |
| open my $fh, "$wget $uri -O - |" or die "wget $uri: $!"; | |
| @@ -29,10 +29,8 @@ if (eval { require LWP::Simple }) { | |
| } | |
| # TODO curl | |
| -my $tar = `which tar`; | |
| -chomp $tar; | |
| -if(-x $tar){ | |
| +if(my $tar = which 'tar'){ | |
| *untar = sub { | |
| my($tarfile) = @_; | |
| @@ -159,3 +157,17 @@ sub find_module { | |
| return; | |
| } | |
| + | |
| +sub which { | |
| + my($name) = @_; | |
| + my $exe_ext = $Config{_exe}; | |
| + warn "which $name...\n"; | |
| + foreach my $dir(File::Spec->path){ | |
| + my $fullpath = File::Spec->catfile($dir, $name); | |
| + if(-x $fullpath || -x ($fullpath .= $exe_ext)){ | |
| + warn " using: $fullpath\n"; | |
| + return $fullpath; | |
| + } | |
| + } | |
| + return undef; | |
| +} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment