Fix env to work for Makefile.PL too.
Dan Brook [Mon, 1 Nov 2010 21:55:57 +0000 (21:55 +0000)]
Rewrote $lookup so it is now sane and does what it says in the comment:
looks up the directory structure until it finds a Makefile.PL or hits
the root directory (aka the error condition).

script/env

index c1d23d7..8256541 100755 (executable)
@@ -31,21 +31,17 @@ use Carp;
 use lib;
 use FindBin;
 use File::Spec ();
+use Cwd ();
 
 # Look up to see find Makefile.PL aka the base of the local::lib install.
 my $lookup; $lookup = sub {
-    my $dir = $_[0] || '.';
+    my $dir = $_[0] || $FindBin::Bin;
 
-    my(undef, $dirbit) = File::Spec->splitpath($FindBin::Bin);
-    my $trydir         = File::Spec->catdir($dirbit, $dir);
+    return '' if Cwd::abs_path($dir) eq File::Spec->rootdir;
 
-    return '' unless -d $trydir;
+    my $tryfile = File::Spec->catfile($dir, "Makefile.PL");
 
-    my $tryfile = File::Spec->catfile($trydir, "Makefile.PL");
-
-    return $trydir if -r $tryfile;
-
-    return $lookup->( File::Spec->catdir($trydir, File::Spec->updir) );
+    return -r $tryfile ? $dir : $lookup->( File::Spec->catdir($dir, File::Spec->updir) );
 };
 
 my $basedir = $lookup->();