Re: CPANPLUS working again on VMS Re: [PATCH@32279] Upgrade File::Fetch to 0.13_04...
[p5sagit/p5-mst-13.2.git] / lib / CPANPLUS / Config.pm
index b092133..89de280 100644 (file)
@@ -486,18 +486,42 @@ remains empty if you do not require super user permissiosn to install.
 =cut
 
         $Conf->{'program'}->{'sudo'} = do {
-            $>  # check for all install dirs!
-                # installsiteman3dir is a 5.8'ism.. don't check
-                # it on 5.6.x...
-                ? ( -w $Config{'installsitelib'} &&
-                    ( defined $Config{'installsiteman3dir'} &&
-                           -w $Config{'installsiteman3dir'}
-                    ) &&
-                    -w $Config{'installsitebin'} 
-                        ? undef
-                        : can_run('sudo') 
-                  )
-                : can_run('sudo')
+
+            ### let's assume you dont need sudo,
+            ### unless one of the below criteria tells us otherwise
+            my $sudo = undef;
+            
+            ### you're a normal user, you might need sudo
+            if( $> ) {
+    
+                ### check for all install dirs!
+                ### installsiteman3dir is a 5.8'ism.. don't check
+                ### it on 5.6.x...            
+                ### you have write permissions to the installdir,
+                ### you don't need sudo
+                if( -w $Config{'installsitelib'} &&
+                    ( defined $Config{'installsiteman3dir'} && 
+                      -w $Config{'installsiteman3dir'} 
+                    ) && -w $Config{'installsitebin'} 
+                ) {                    
+                    $sudo = undef;
+                    
+                ### you have PERL_MM_OPT set to some alternate
+                ### install place. You probably have write permissions
+                ### to that
+                } elsif ( $ENV{'PERL_MM_OPT'} and 
+                          $ENV{'PERL_MM_OPT'} =~ /INSTALL|LIB|PREFIX/
+                ) {
+                    $sudo = undef;
+
+                ### you probably don't have write permissions
+                } else {                
+                    $sudo = can_run('sudo');
+                }
+            }  
+            
+            ### and return the value
+            $sudo;
         };
 
 =item perlwrapper
@@ -531,17 +555,17 @@ with CPANPLUS, which is used to enable autoflushing in spawned processes.
 
             my $path;
             BIN: for my $bin (@bins) {
-                
+
                 ### parallel to your cpanp/cpanp-boxed
                 my $maybe = File::Spec->rel2abs(
-                                File::Spec->catdir( dirname($0), $bin )
+                                File::Spec->catfile( dirname($0), $bin )
                             );        
                 $path = $maybe and last BIN if -f $maybe;
         
                 ### parallel to your CPANPLUS.pm:
                 ### $INC{cpanplus}/../bin/cpanp-run-perl
                 $maybe = File::Spec->rel2abs(
-                            File::Spec->catdir( 
+                            File::Spec->catfile( 
                                 dirname($INC{'CPANPLUS.pm'}),
                                 '..',   # lib dir
                                 'bin',  # bin dir
@@ -556,7 +580,7 @@ with CPANPLUS, which is used to enable autoflushing in spawned processes.
                 ### CPANPLUS.pm in
                 ### /tmp/cp/lib/perl5/site_perl/5.8.8
                 $maybe = File::Spec->rel2abs(
-                            File::Spec->catdir( 
+                            File::Spec->catfile( 
                                 dirname( $INC{'CPANPLUS.pm'} ),
                                 '..', '..', '..', '..', # 4x updir
                                 'bin',                  # bin dir
@@ -575,6 +599,11 @@ with CPANPLUS, which is used to enable autoflushing in spawned processes.
                              split(/\Q$Config::Config{path_sep}\E/, $ENV{PATH}),
                              File::Spec->curdir, 
                 ) {             
+
+                    ### On VMS the path could be in UNIX format, and we
+                    ### currently need it to be in VMS format
+                    $dir = VMS::Filespec::vmspath($dir) if ON_VMS;
+
                     $maybe = File::Spec->catfile( $dir, $bin );
                     $path = $maybe and last BIN if -f $maybe;
                 }