28
31
# This is not enforced yet, but will be some time in the next few
29
32
# releases once we can make sure it won't clash with custom
30
33
# Module::Install extensions.
33
36
# Storage for the pseudo-singleton
45
# Whether or not inc::Module::Install is actually loaded, the
46
# $INC{inc/Module/Install.pm} is what will still get set as long as
47
# the caller loaded module this in the documented manner.
48
# If not set, the caller may NOT have loaded the bundled version, and thus
49
# they may not have a MI version that works with the Makefile.PL. This would
50
# result in false errors or unexpected behaviour. And we don't want that.
51
my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm';
52
unless ( $INC{$file} ) { die <<"END_DIE" }
46
my $self = $class->new(@_);
47
my $who = $self->_caller;
49
#-------------------------------------------------------------
50
# all of the following checks should be included in import(),
51
# to allow "eval 'require Module::Install; 1' to test
52
# installation of Module::Install. (RT #51267)
53
#-------------------------------------------------------------
55
# Whether or not inc::Module::Install is actually loaded, the
56
# $INC{inc/Module/Install.pm} is what will still get set as long as
57
# the caller loaded module this in the documented manner.
58
# If not set, the caller may NOT have loaded the bundled version, and thus
59
# they may not have a MI version that works with the Makefile.PL. This would
60
# result in false errors or unexpected behaviour. And we don't want that.
61
my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm';
62
unless ( $INC{$file} ) { die <<"END_DIE" }
54
64
Please invoke ${\__PACKAGE__} with:
68
# If the script that is loading Module::Install is from the future,
69
# then make will detect this and cause it to re-run over and over
70
# again. This is bad. Rather than taking action to touch it (which
71
# is unreliable on some platforms and requires write permissions)
72
# for now we should catch this and refuse to run.
74
my $s = (stat($0))[9];
76
# If the modification time is only slightly in the future,
77
# sleep briefly to remove the problem.
79
if ( $a > 0 and $a < 5 ) { sleep 5 }
81
# Too far in the future, throw an error.
83
if ( $s > $t ) { die <<"END_DIE" }
74
# This reportedly fixes a rare Win32 UTC file time issue, but
75
# as this is a non-cross-platform XS module not in the core,
76
# we shouldn't really depend on it. See RT #24194 for detail.
77
# (Also, this module only supports Perl 5.6 and above).
78
eval "use Win32::UTCFileTime" if $^O eq 'MSWin32' && $] >= 5.006;
80
# If the script that is loading Module::Install is from the future,
81
# then make will detect this and cause it to re-run over and over
82
# again. This is bad. Rather than taking action to touch it (which
83
# is unreliable on some platforms and requires write permissions)
84
# for now we should catch this and refuse to run.
86
my $s = (stat($0))[9];
88
# If the modification time is only slightly in the future,
89
# sleep briefly to remove the problem.
91
if ( $a > 0 and $a < 5 ) { sleep 5 }
93
# Too far in the future, throw an error.
95
if ( $s > $t ) { die <<"END_DIE" }
85
97
Your installer $0 has a modification time in the future ($s > $t).
89
101
Please correct this, then run $0 again.
98
# Build.PL was formerly supported, but no longer is due to excessive
99
# difficulty in implementing every single feature twice.
100
if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" }
107
# Build.PL was formerly supported, but no longer is due to excessive
108
# difficulty in implementing every single feature twice.
109
if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" }
102
111
Module::Install no longer supports Build.PL.
114
# To save some more typing in Module::Install installers, every...
115
# use inc::Module::Install
116
# ...also acts as an implicit use strict.
117
$^H |= strict::bits(qw(refs subs vars));
119
#-------------------------------------------------------------
121
# To save some more typing in Module::Install installers, every...
122
# use inc::Module::Install
123
# ...also acts as an implicit use strict.
124
$^H |= strict::bits(qw(refs subs vars));
126
#-------------------------------------------------------------
128
unless ( -f $self->{file} ) {
129
foreach my $key (keys %INC) {
130
delete $INC{$key} if $key =~ /Module\/Install/;
134
require "$self->{path}/$self->{dispatch}.pm";
135
File::Path::mkpath("$self->{prefix}/$self->{author}");
136
$self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self );
137
$self->{admin}->init;
138
@_ = ($class, _self => $self);
139
goto &{"$self->{name}::import"};
143
*{"${who}::AUTOLOAD"} = $self->autoload;
146
# Unregister loader and worker packages so subdirs can use them again
147
delete $INC{'inc/Module/Install.pm'};
148
delete $INC{'Module/Install.pm'};
150
# Save to the singleton
129
157
my $self = shift;
136
164
# Delegate back to parent dirs
137
165
goto &$code unless $cwd eq $pwd;
139
$$sym =~ /([^:]+)$/ or die "Cannot autoload $who - $sym";
167
unless ($$sym =~ s/([^:]+)$//) {
168
# XXX: it looks like we can't retrieve the missing function
169
# via $$sym (usually $main::AUTOLOAD) in this case.
170
# I'm still wondering if we should slurp Makefile.PL to
171
# get some context or not ...
172
my ($package, $file, $line) = caller;
174
Unknown function is found at $file line $line.
175
Execution of $file aborted due to runtime errors.
177
If you're a contributor to a project, you may need to install
178
some Module::Install extensions from CPAN (or other repository).
179
If you're a user of a module, please contact the author.
141
183
if ( uc($method) eq $method ) {
157
my $self = $class->new(@_);
158
my $who = $self->_caller;
160
unless ( -f $self->{file} ) {
161
require "$self->{path}/$self->{dispatch}.pm";
162
File::Path::mkpath("$self->{prefix}/$self->{author}");
163
$self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self );
164
$self->{admin}->init;
165
@_ = ($class, _self => $self);
166
goto &{"$self->{name}::import"};
169
*{"${who}::AUTOLOAD"} = $self->autoload;
172
# Unregister loader and worker packages so subdirs can use them again
173
delete $INC{"$self->{file}"};
174
delete $INC{"$self->{path}.pm"};
176
# Save to the singleton
183
198
my $self = shift;
184
199
unless ( $self->{extensions} ) {
205
220
my $who = $self->_caller;
206
221
foreach my $name ( sort keys %seen ) {
207
223
*{"${who}::$name"} = sub {
208
224
${"${who}::AUTOLOAD"} = "${who}::$name";
209
225
goto &{"${who}::AUTOLOAD"};
215
231
my ($class, %args) = @_;
233
delete $INC{'FindBin.pm'};
235
# to suppress the redefine warning
236
local $SIG{__WARN__} = sub {};
217
240
# ignore the prefix on extension modules built from top level.
218
241
my $base_path = Cwd::abs_path($FindBin::Bin);
219
242
unless ( Cwd::abs_path(Cwd::cwd()) eq $base_path ) {
220
243
delete $args{prefix};
223
245
return $args{_self} if $args{_self};
225
247
$args{dispatch} ||= 'Admin';
272
294
sub load_extensions {
273
295
my ($self, $path, $top) = @_;
297
my $should_reload = 0;
275
298
unless ( grep { ! ref $_ and lc $_ eq lc $self->{prefix} } @INC ) {
276
299
unshift @INC, $self->{prefix};
279
303
foreach my $rv ( $self->find_extensions($path) ) {
281
305
next if $self->{pathnames}{$pkg};
284
my $new = eval { require $file; $pkg->can('new') };
308
my $new = eval { local $^W; require $file; $pkg->can('new') };
285
309
unless ( $new ) {
289
$self->{pathnames}{$pkg} = delete $INC{$file};
313
$self->{pathnames}{$pkg} =
314
$should_reload ? delete $INC{$file} : $INC{$file};
290
315
push @{$self->{extensions}}, &{$new}($pkg, _top => $top );
354
open( FH, '<', $_[0] ) or die "open($_[0]): $!";
356
open( FH, "< $_[0]" ) or die "open($_[0]): $!";
358
my $string = do { local $/; <FH> };
359
close FH or die "close($_[0]): $!";
376
# Done in evals to avoid confusing Perl::MinimumVersion
377
eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@;
380
open( FH, '<', $_[0] ) or die "open($_[0]): $!";
381
my $string = do { local $/; <FH> };
382
close FH or die "close($_[0]): $!";
388
open( FH, "< $_[0]" ) or die "open($_[0]): $!";
389
my $string = do { local $/; <FH> };
390
close FH or die "close($_[0]): $!";
364
396
my $string = Module::Install::_read($_[0]);
385
open( FH, '>', $_[0] ) or die "open($_[0]): $!";
387
open( FH, "> $_[0]" ) or die "open($_[0]): $!";
389
foreach ( 1 .. $#_ ) {
390
print FH $_[$_] or die "print($_[0]): $!";
392
close FH or die "close($_[0]): $!";
414
# Done in evals to avoid confusing Perl::MinimumVersion
415
eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@;
418
open( FH, '>', $_[0] ) or die "open($_[0]): $!";
419
foreach ( 1 .. $#_ ) {
420
print FH $_[$_] or die "print($_[0]): $!";
422
close FH or die "close($_[0]): $!";
427
open( FH, "> $_[0]" ) or die "open($_[0]): $!";
428
foreach ( 1 .. $#_ ) {
429
print FH $_[$_] or die "print($_[0]): $!";
431
close FH or die "close($_[0]): $!";
395
435
# _version is for processing module versions (eg, 1.03_05) not
396
436
# Perl versions (eg, 5.8.1).