Skip to content

Instantly share code, notes, and snippets.

@gfx
Created February 19, 2010 10:19
Show Gist options
  • Select an option

  • Save gfx/308611 to your computer and use it in GitHub Desktop.

Select an option

Save gfx/308611 to your computer and use it in GitHub Desktop.
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