Debian Codegraph @

bin/cpanp-boxed

raw
1 #!/usr/bin/perl -w
2
3 ### Setup a "Good" Copy of @INC to use at runtime, and a
4 ### temporary one to use at bootstrap time.
5 BEGIN {
6 use strict;
7 use warnings;
8
9 use Config;
10 use FindBin;
11 use File::Spec;
12 use File::Spec::Unix;
13
14 use vars qw[@RUN_TIME_INC $LIB_DIR $BUNDLE_DIR $BASE $PRIV_LIB];
15 $LIB_DIR = File::Spec->catdir( $FindBin::Bin, qw[.. lib] );
16 $BUNDLE_DIR = File::Spec->catdir( $FindBin::Bin, qw[.. inc bundle] );
17
18 ### must set the PERL5LIB env var here as well, as some
19 ### code in CPANPLUS resets it between iterations. So we
20 ### have to set our 'final' perl5lib before loading any
21 ### CPANPLUS code. The constants code is 'safe' but better
22 ### safe than sorry. So duplicating the 'constants' behaviour
23 ### of DOT_CPANPLUS
24 # use CPANPLUS::Internals::Constants;
25 my $who = getlogin || getpwuid($<) || $<;
26 $BASE = File::Spec->catfile(
27 $FindBin::Bin, '..', '.cpanplus', $who);
28 $PRIV_LIB = File::Spec->catfile( $BASE, 'lib' );
29
30 @RUN_TIME_INC = ($PRIV_LIB, @INC);
31 unshift @INC, $LIB_DIR, $BUNDLE_DIR;
32
33 ### set it in the environment too, for when we shell out
34 ### (like at 'perl makefile.pl' time.
35 $ENV{'PERL5LIB'} = join $Config{'path_sep'}, grep { defined }
36 $PRIV_LIB, # to find the boxed config
37 #$LIB_DIR, # the CPANPLUS libs
38 $ENV{'PERL5LIB'}; # original PERL5LIB
39
40 }
41
42 use FindBin;
43 use File::Find qw[find];
44 use CPANPLUS::Error;
45 use CPANPLUS::Configure;
46 use CPANPLUS::Internals::Constants;
47 use CPANPLUS::Internals::Utils;
48
49 ### now, load in all the .pms from the bundle dir, so they're in
50 ### memory. Skip the ones already loaded, and ignore failed requires.
51 ### XXX this section *somehow* makes 'system(cmd.exe)' return immediately
52 ### on win32, when run from cpanp-boxed (regular cpanp is fine). Probably
53 ### need to load only a subsection of these modules, for safety sake.
54 { for my $dir ( ($BUNDLE_DIR, $LIB_DIR) ) {
55 my $base_re = quotemeta $dir;
56
57 find( sub { my $file = $File::Find::name;
58 return unless -e $file && -f _ && -s _;
59
60 return if $file =~ /\._/; # osx temp files
61
62 ### strip base dir. Might not end in / (or local
63 ### dir delimiter), so remove that if needed too
64 $file =~ s/^$base_re(\W)?//;
65
66 ### file already loaded.
67 return if $INC{$file};
68
69 ### construct pm name and strip suffix
70 my $unixfile = File::Spec::Unix->catfile(
71 File::Spec->splitdir( $file )
72 );
73 my $pm = join '::', File::Spec->splitdir( $file );
74 $pm =~ s/\.pm$//i or return; # not a .pm file
75
76 ### make sure we *DONT* load these blatantly
77 #return if $pm =~ /(?:IPC::Run::)|(?:File::Spec::)/;
78
79 eval "require $pm ; 1";
80
81 ### if the require *FAILS* it's still added to %INC
82 ### in some cases (mostly if a require in the required
83 ### file fails or some such.. so remove it from our %INC!
84 if( $@ ) {
85 push @failures, $unixfile;
86
87 ### dont enable warnings -- some modules
88 ### are OS specific. Uncomment only for debug
89 ### reasons
90 #warn $@;
91
92
93 }
94 }, $dir );
95 }
96
97 ### delete AFTER we've loaded everything!
98 delete $INC{$_} for @failures;
99
100 ### set @INC back to our non-bundled version
101 @INC = @RUN_TIME_INC;
102 }
103
104
105 ### setup the configuration
106 my $ConfObj = CPANPLUS::Configure->new;
107 my $Config = CONFIG_BOXED;
108 my $Util = 'CPANPLUS::Internals::Utils';
109 my $ConfigFile = $ConfObj->_config_pm_to_file( $Config => $PRIV_LIB );
110 my $AutoFlush = File::Spec->catfile( $PRIV_LIB, split('::','CPANPLUS::Internals::Utils::Autoflush.pm') );
111
112 ### setup the environment if needed
113 { ### no base dir even, set it up
114 unless( IS_DIR->( $BASE ) ) {
115 $Util->_mkdir( dir => $BASE ) or die CPANPLUS::Error->stack_as_string;
116 }
117
118 ### no config file exists yet, so we create it
119 unless( -e $ConfigFile ) {
120 ### alter what needs changing
121 $ConfObj->set_conf( base => $BASE ); # new base dir
122 $ConfObj->set_conf( verbose => 1 ); # be verbose
123 $ConfObj->set_conf( prereqs => 1 ); # install prereqs
124 $ConfObj->save( $Config => $PRIV_LIB ); # save the pm in that dir
125 }
126
127 ### no Autoflush exists yet, copy it from lib/
128 unless( -e $AutoFlush ) {
129 my $targ = File::Spec->catdir( $PRIV_LIB, split('::','CPANPLUS::Internals::Utils') );
130 $Util->_mkdir( dir => $targ );
131 $Util->_copy(
132 file => File::Spec->catfile( $LIB_DIR, split('::','CPANPLUS::Internals::Utils::Autoflush.pm') ),
133 to => $targ,
134 ) or die CPANPLUS::Error->stack_as_string;
135 }
136 }
137
138 print qq[
139 ===
140
141 Your boxed CPANPLUS install is setup to use:
142 Basedir: $BASE
143 Config: $ConfigFile
144
145 If you wish to save your boxed configuration, please type:
146 s save boxed
147
148 You can bootstrap your CPANPLUS by running:
149 s selfupdate dependencies
150 s selfupdate enabled_features
151
152 ===
153 \n
154 ];
155
156 ### set the @INC to a runtime version, so our bundled modules
157 ### are 'hidden' from probing, but loaded already for 'use' and
158 ### 'require' statements
159
160 { $Module::Load::Conditional::CHECK_INC_HASH = 1;
161 do File::Spec->catfile( $FindBin::Bin, 'cpanp' ) or die "$! $@";
162 }