Moved Log::Message::Simple from lib/ to ext/
[p5sagit/p5-mst-13.2.git] / lib / CPANPLUS / Config.pm
index b092133..28f4fb6 100644 (file)
@@ -26,6 +26,23 @@ use Module::Load::Conditional   qw[check_install];
 
 CPANPLUS::Config
 
+=head1 SYNOPSIS
+
+    ### conf object via CPANPLUS::Backend;
+    $cb   = CPANPLUS::Backend->new;
+    $conf = $cb->configure_object;
+    
+    ### or as a standalone object
+    $conf = CPANPLUS::Configure->new;
+
+    ### values in 'conf' section
+    $verbose = $conf->get_conf( 'verbose' );    
+    $conf->set_conf( verbose => 1 );
+
+    ### values in 'program' section
+    $editor = $conf->get_program( 'editor' );
+    $conf->set_program( editor => '/bin/vi' );
+
 =head1 DESCRIPTION
 
 This module contains defaults and heuristics for configuration 
@@ -134,7 +151,7 @@ are run interactively or not. Defaults to 'true'.
 
 =item base
 
-The directory CPANPLUS keeps all it's build and state information in.
+The directory CPANPLUS keeps all its build and state information in.
 Defaults to ~/.cpanplus.
 
 =cut
@@ -197,6 +214,20 @@ when sending emails. Defaults to an C<example.com> address.
 =cut
 
         $Conf->{'conf'}->{'email'} = DEFAULT_EMAIL;
+        
+=item enable_custom_sources
+
+Boolean flag indicating whether custom sources should be enabled or
+not. See the C<CUSTOM MODULE SOURCES> in C<CPANPLUS::Backend> for
+details on how to use them.
+
+Defaults to C<true>
+
+=cut
+
+        ### this addresses #32248 which requests a possibillity to
+        ### turn off custom sources
+        $Conf->{'conf'}->{'enable_custom_sources'} = 1;
 
 =item extractdir
 
@@ -419,6 +450,29 @@ a module using the interactive shell. Defaults to 'true'.
 
         $Conf->{'conf'}->{'write_install_logs'} = 1;
 
+=item source_engine
+
+Class to use as the source engine, which is generally a subclass of
+C<CPANPLUS::Internals::Source>. Default to C<CPANPLUS::Internals::Source::Memory>.
+
+=cut
+
+        $Conf->{'conf'}->{'source_engine'} = DEFAULT_SOURCE_ENGINE; 
+
+=item cpantest_reporter_args
+
+A hashref of key => value pairs that are passed to the constructor
+of C<Test::Reporter>. If you'd want to enable TLS for example, you'd
+set it to:
+
+  { transport       => 'Net::SMTP::TLS',
+    transport_args  => [ User => 'Joe', Password => '123' ],
+  }  
+
+=cut
+
+        $Conf->{'conf'}->{'cpantest_reporter_args'} = {};
+
 =back
     
 =head2 Section 'program'
@@ -433,7 +487,7 @@ a module using the interactive shell. Defaults to 'true'.
 =item editor
 
 A string holding the path to your editor of choice. Defaults to your
-$ENV{EDITOR}, $ENV{VISIUAL}, 'vi' or 'pico' programs, in that order.
+$ENV{EDITOR}, $ENV{VISUAL}, 'vi' or 'pico' programs, in that order.
 
 =cut
 
@@ -486,18 +540,44 @@ 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!
+                ### you have write permissions to the installdir,
+                ### you don't need sudo
+                if( -w $Config{'installsitelib'} && -w $Config{'installsitebin'} ) {                    
+                    
+                    ### installsiteman3dir is a 5.8'ism.. don't check
+                    ### it on 5.6.x...            
+                    if( defined $Config{'installsiteman3dir'} ) {
+                        $sudo = -w $Config{'installsiteman3dir'} 
+                            ? undef
+                            : can_run('sudo');
+                    } else {
+                        $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
@@ -534,14 +614,14 @@ with CPANPLUS, which is used to enable autoflushing in spawned processes.
                 
                 ### 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 +636,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 +655,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;
                 }