diff options
author | Craig A. Berry <craigberry@mac.com> | 2011-01-23 18:30:56 -0600 |
---|---|---|
committer | Craig A. Berry <craigberry@mac.com> | 2011-01-23 18:30:56 -0600 |
commit | 613e98e463d92e7eb6bfa6d25de65632ece7d50f (patch) | |
tree | 0f860f23051c084fc60059f7418c88410db41162 /cpan | |
parent | 25bab59bcdd24a506b9bafa5b170e8ed99c07487 (diff) | |
download | perl-613e98e463d92e7eb6bfa6d25de65632ece7d50f.tar.gz |
Split shebang line fix-up from file processing in MM->fixin().
By putting the shebang line gyrations on their own in the new
_fixin_replace_shebang method, we can override that part without
dragging along the file processing code.
Tracks upstream commit:
https://github.com/Perl-Toolchain-Gang/ExtUtils-MakeMaker/commit/33d7db29a2adb5bbb12fb2a783063245fe58dfc1
Diffstat (limited to 'cpan')
-rw-r--r-- | cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm | 111 |
1 files changed, 59 insertions, 52 deletions
diff --git a/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm b/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm index 0310fd702d..6964eea088 100644 --- a/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm +++ b/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm @@ -1079,7 +1079,6 @@ Inserts the sharpbang or equivalent magic number to a set of @files. sub fixin { # stolen from the pink Camel book, more or less my ( $self, @files ) = @_; - my ($does_shbang) = $Config{'sharpbang'} =~ /^\s*\#\!/; for my $file (@files) { my $file_new = "$file.new"; my $file_bak = "$file.bak"; @@ -1088,58 +1087,9 @@ sub fixin { # stolen from the pink Camel book, more or less local $/ = "\n"; chomp( my $line = <$fixin> ); next unless $line =~ s/^\s*\#!\s*//; # Not a shbang file. - # Now figure out the interpreter name. - my ( $cmd, $arg ) = split ' ', $line, 2; - $cmd =~ s!^.*/!!; - - # Now look (in reverse) for interpreter in absolute PATH (unless perl). - my $interpreter; - if ( $cmd =~ m{^perl(?:\z|[^a-z])} ) { - if ( $Config{startperl} =~ m,^\#!.*/perl, ) { - $interpreter = $Config{startperl}; - $interpreter =~ s,^\#!,,; - } - else { - $interpreter = $Config{perlpath}; - } - } - else { - my (@absdirs) - = reverse grep { $self->file_name_is_absolute($_) } $self->path; - $interpreter = ''; - - foreach my $dir (@absdirs) { - if ( $self->maybe_command($cmd) ) { - warn "Ignoring $interpreter in $file\n" - if $Verbose && $interpreter; - $interpreter = $self->catfile( $dir, $cmd ); - } - } - } - - # Figure out how to invoke interpreter on this machine. - my ($shb) = ""; - if ($interpreter) { - print STDOUT "Changing sharpbang in $file to $interpreter" - if $Verbose; - - # this is probably value-free on DOSISH platforms - if ($does_shbang) { - $shb .= "$Config{'sharpbang'}$interpreter"; - $shb .= ' ' . $arg if defined $arg; - $shb .= "\n"; - } - $shb .= qq{ -eval 'exec $interpreter $arg -S \$0 \${1+"\$\@"}' - if 0; # not running under some shell -} unless $Is{Win32}; # this won't work on win32, so don't - } - else { - warn "Can't find $cmd in PATH, $file unchanged" - if $Verbose; - next; - } + my $shb = $self->_fixin_replace_shebang( $file, $line ); + next unless defined $shb; open( my $fixout, ">", "$file_new" ) or do { warn "Can't create new $file: $!\n"; @@ -1189,6 +1139,63 @@ sub _rename { return rename($old, $new); } +sub _fixin_replace_shebang { + my ( $self, $file, $line ) = @_; + + # Now figure out the interpreter name. + my ( $cmd, $arg ) = split ' ', $line, 2; + $cmd =~ s!^.*/!!; + + # Now look (in reverse) for interpreter in absolute PATH (unless perl). + my $interpreter; + if ( $cmd =~ m{^perl(?:\z|[^a-z])} ) { + if ( $Config{startperl} =~ m,^\#!.*/perl, ) { + $interpreter = $Config{startperl}; + $interpreter =~ s,^\#!,,; + } + else { + $interpreter = $Config{perlpath}; + } + } + else { + my (@absdirs) + = reverse grep { $self->file_name_is_absolute($_) } $self->path; + $interpreter = ''; + + foreach my $dir (@absdirs) { + if ( $self->maybe_command($cmd) ) { + warn "Ignoring $interpreter in $file\n" + if $Verbose && $interpreter; + $interpreter = $self->catfile( $dir, $cmd ); + } + } + } + + # Figure out how to invoke interpreter on this machine. + + my ($does_shbang) = $Config{'sharpbang'} =~ /^\s*\#\!/; + my ($shb) = ""; + if ($interpreter) { + print STDOUT "Changing sharpbang in $file to $interpreter" + if $Verbose; + # this is probably value-free on DOSISH platforms + if ($does_shbang) { + $shb .= "$Config{'sharpbang'}$interpreter"; + $shb .= ' ' . $arg if defined $arg; + $shb .= "\n"; + } + $shb .= qq{ +eval 'exec $interpreter $arg -S \$0 \${1+"\$\@"}' + if 0; # not running under some shell +} unless $Is{Win32}; # this won't work on win32, so don't + } + else { + warn "Can't find $cmd in PATH, $file unchanged" + if $Verbose; + return undef; + } + return $shb +} =item force (o) |