Re: Shortest path to a MyConfig

[email protected] (Tyler MacDonald)
Newsgroups perl.cpan.discuss
Message-ID <[email protected]>
Tyler MacDonald <[email protected]> wrote:
> brian d foy <[email protected]> wrote:
> > > > If yes, I think I'd call it "mkmyconfig".
> > > > 
> > > > And when you could please add a paragraph of documentation, it's in in
> > > > a second.
> > > 
> > >  OK, I'll re-do my patch with a snippet of docs. I didn't really
> > > consider that somebody might explicitly run
> > > 
> > >  perl -MCPAN -e 'mkmyconfig'
> > 
> > Perhaps this is something I can add to the cpan(1) script.
> 
> 	That'd be great! I'll be submitting my refined CPAN.pm patch w/docs
> tonight.

	OK, here's the patch! I noticed there's no docs on installing
dev.releases or automatic installation, so I threw those in as well. LMK
what you think.

		- Tyler
myconfig.patch (text/plain, 3.7 KB)
diff -dur CPAN-1.83_59.orig/lib/CPAN.pm CPAN-1.83_59/lib/CPAN.pm
--- CPAN-1.83_59.orig/lib/CPAN.pm	2006-01-29 13:46:58.000000000 -0800
+++ CPAN-1.83_59/lib/CPAN.pm	2006-01-30 19:14:00.000000000 -0800
@@ -54,7 +54,7 @@
 @EXPORT = qw(
 	     autobundle bundle expand force notest get cvs_import
 	     install make readme recompile shell test clean
-             perldoc recent
+             perldoc recent mkmyconfig
 	    );
 
 sub soft_chdir_with_alternatives ($);
@@ -238,6 +238,27 @@
         }
     }
 }
+
+#-> sub CPAN::mkmyconfig ;
+sub mkmyconfig {
+    my($cpanpm, %args) = @_;
+    require CPAN::FirstTime;
+    $cpanpm = $INC{'CPAN/MyConfig.pm'} || "$ENV{HOME}/.cpan/CPAN/MyConfig.pm";
+    File::Path::mkpath(File::Basename::dirname($cpanpm)) unless -e $cpanpm;
+    if(!$INC{'CPAN/Config.pm'}) {
+        eval { require CPAN::Config; };
+    }
+    $CPAN::Config ||= {};
+    $CPAN::Config = {
+        %$CPAN::Config,
+        build_dir           =>  undef,
+        cpan_home           =>  undef,
+        keep_source_where   =>  undef,
+        histfile            =>  undef,
+    };
+    CPAN::FirstTime::init($cpanpm, %args);
+}
+
 package CPAN::CacheMgr;
 use strict;
 @CPAN::CacheMgr::ISA = qw(CPAN::InfoObj CPAN);
@@ -675,8 +696,15 @@
     $incc
 or
     $myincc
-
 });
+        if(!$INC{'CPAN/MyConfig.pm'}) {
+            $CPAN::Frontend->myprint("You don't seem to have a user configuration (MyConfig.pm) yet.\n");
+            my $new = ExtUtils::MakeMaker::prompt("Do you want to create a user configuration now?", "yes");
+            if($new =~ m{^y}i) {
+                CPAN::mkmyconfig();
+                return &checklock;
+            }
+        }
 	}
 	$CPAN::Frontend->mydie("Could not open >$lockfile: $!");
     }
@@ -7643,15 +7671,18 @@
 I am not root, how can I install a module in a personal directory?
 
 First of all, you will want to use your own configuration, not the one
-that your root user installed. The following command sequence is a
-possible approach:
+that your root user installed. If you do not have permission to write
+in the cpan directory that root has configured, you will be asked if
+you want to create your own config. Answering "yes" will bring you into
+CPAN's configuration stage, using the system config for all defaults except
+things that have to do with CPAN's work directory, saving your choices to
+your MyConfig.pm file.
 
-    % mkdir -p $HOME/.cpan/CPAN
-    % echo '1;' > $HOME/.cpan/CPAN/MyConfig.pm
-    % cpan
-    [...answer all questions...]
+You can also manually initiate this process with the following command:
 
-You will most probably like something like this:
+    % perl -MCPAN -e 'mkmyconfig'
+
+You will most probably also want to configure something like this:
 
   o conf makepl_arg "LIB=~/myperl/lib \
                     INSTALLMAN1DIR=~/myperl/man/man1 \
@@ -7768,6 +7799,29 @@
 but this is neither guaranteed to work in the future nor is it a
 decent command.
 
+=item 12)
+
+How do I install a "DEVELOPER RELEASE" of a module?
+
+By default, CPAN will install the latest non-developer release of a module.
+If you want to install a dev release, you have to specify a partial path to
+the tarball you wish to install, like so:
+
+    cpan> install KWILLIAMS/Module-Build-0.27_06.tar.gz
+
+=item 13)
+
+How do I install a module and all it's dependancies from the commandline,
+without being prompted for anything, despite my CPAN configuration
+(or lack thereof)?
+
+CPAN uses ExtUtils::MakeMaker's prompt() function to ask it's questions, so
+if you set the PERL_MM_USE_DEFAULT environment variable, you shouldn't be
+asked any questions at all (assuming the modules you are installing are
+nice about obeying that variable as well):
+
+    % PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install My::Module'
+
 =back
 
 =head1 BUGS
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.