Re: sitecustomize.pl [PATCH]
authorGisle Aas <gisle@aas.no>
Fri, 18 Mar 2005 04:06:40 +0000 (20:06 -0800)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Fri, 18 Mar 2005 14:02:36 +0000 (14:02 +0000)
Message-ID: <lru0n9w433.fsf@caliper.activestate.com>

Adds a new command-line switch, -f, and a new optional
compile-time setting -DUSE_SITECUSTOMIZE

p4raw-id: //depot/perl@24043

INSTALL
ext/Devel/DProf/t/DProf.t
perl.c
pod/perlrun.pod

diff --git a/INSTALL b/INSTALL
index c7e0a06..fb2d5cd 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -845,6 +845,16 @@ present, at run time.  Of course, you can still search other @INC
 directories ahead of those in APPLLIB_EXP by using any of the standard
 run-time methods: $PERLLIB, $PERL5LIB, -I, use lib, etc.
 
+=item USE_SITECUSTOMIZE
+
+Run-time customization of @INC can be enabled with:
+
+       sh Configure -Accflags=-DUSE_SITECUSTOMIZE
+
+When enabled, make perl run F<$sitelibexp/sitecustomize.pl> before
+anything else.  This script can then be set up to add additional
+entries to @INC.
+
 =item Man Pages
 
 In versions 5.005_57 and earlier, the default was to store module man
index 3488bc8..bdd70b0 100644 (file)
@@ -48,7 +48,7 @@ sub profile {
        my $opt_d = '-d:DProf';
 
        my $t_start = new Benchmark;
-        open( R, "$perl \"$opt_d\" $test |" ) || warn "$0: Can't run. $!\n";
+        open( R, "$perl -f \"$opt_d\" $test |" ) || warn "$0: Can't run. $!\n";
        @results = <R>;
        close R or warn "Could not close: $!";
        my $t_total = timediff( new Benchmark, $t_start );
diff --git a/perl.c b/perl.c
index 96b3a5a..7974a42 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -1229,6 +1229,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
     register SV *sv;
     register char *s;
     char *cddir = Nullch;
+    bool minus_f = FALSE;
 
     PL_fdscript = -1;
     PL_suidscript = -1;
@@ -1322,6 +1323,11 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
            sv_catpv(PL_e_script, "\n");
            break;
 
+       case 'f':
+           minus_f = TRUE;
+           s++;
+           goto reswitch;
+
        case 'I':       /* -I handled both here and in moreswitches() */
            forbid_setid("-I");
            if (!*++s && (s=argv[1]) != Nullch) {
@@ -1389,6 +1395,9 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
 #  ifdef USE_SOCKS
                sv_catpv(PL_Sv," USE_SOCKS");
 #  endif
+#  ifdef USE_SITECUSTOMIZE
+               sv_catpv(PL_Sv," USE_SITECUSTOMIZE");
+#  endif              
 #  ifdef PERL_IMPLICIT_CONTEXT
                sv_catpv(PL_Sv," PERL_IMPLICIT_CONTEXT");
 #  endif
@@ -1519,6 +1528,15 @@ print \"  \\@INC:\\n    @INC\\n\";");
        }
     }
 
+#ifdef USE_SITECUSTOMIZE
+    if (!minus_f) {
+       if (!PL_preambleav)
+           PL_preambleav = newAV();
+       av_unshift(PL_preambleav, 1);
+       (void)av_store(PL_preambleav, 0, Perl_newSVpvf(aTHX_ "BEGIN { do '%s/sitecustomize.pl' }", SITELIB_EXP));
+    }
+#endif
+
     if (PL_taint_warn && PL_dowarn != G_WARN_ALL_OFF) {
        PL_compiling.cop_warnings = newSVpvn(WARN_TAINTstring, WARNsize);
     }
@@ -2342,6 +2360,7 @@ S_usage(pTHX_ char *name)         /* XXX move this out into a module ? */
 "-d[:debugger]   run program under debugger",
 "-D[number/list] set debugging flags (argument is a bit mask or alphabets)",
 "-e program      one line of program (several -e's allowed, omit programfile)",
+"-f              don't do $sitelib/sitecustomize.pl at startup",
 "-F/pattern/     split() pattern for -a switch (//'s are optional)",
 "-i[extension]   edit <> files in place (makes backup if extension supplied)",
 "-Idirectory     specify @INC/#include directory (several -I's allowed)",
index 1e83bdc..88c5446 100644 (file)
@@ -430,6 +430,17 @@ will not look for a filename in the argument list.  Multiple B<-e>
 commands may be given to build up a multi-line script.  Make sure
 to use semicolons where you would in a normal program.
 
+=item B<-f>
+
+Disable executing F<$Config{siteperl}/sitecustomize.pl> at
+startup.
+
+Perl can be built so that it by default will try to execute
+F<$Config{siteperl}/sitecustomize.pl> at startup.  This is a hook that
+allows the sysadmin to customize how perl behaves.  It can for
+instance be used to add entries to the @INC array to make perl find
+modules in non-standard locations.
+
 =item B<-F>I<pattern>
 
 specifies the pattern to split on if B<-a> is also in effect.  The