Skip to content

Commit

Permalink
Refactor to eliminate 'setlocal' and 'echo off'
Browse files Browse the repository at this point in the history
  • Loading branch information
rivy committed Feb 20, 2019
1 parent 48a9857 commit 6dd1b61
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/ExtUtils/PL2Bat.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,26 @@ sub pl2bat {

my $head = <<"EOT";
\@rem = '--*-Perl-*--
\@setlocal
\@echo off
set "ErrorLevel="
if "%OS%" == "Windows_NT" goto WinNT
perl $opts{otherargs}
set ErrorLevel=%ErrorLevel%
goto endofperl
\@set "ErrorLevel="
\@if "%OS%" == "Windows_NT" \@goto WinNT
\@perl $opts{otherargs}
\@set ErrorLevel=%ErrorLevel%
\@goto endofperl
:WinNT
perl $opts{ntargs}
set ErrorLevel=%ErrorLevel%
if NOT "%COMSPEC%" == "%SystemRoot%\\system32\\cmd.exe" goto endofperl
if %ErrorLevel% == 9009 echo You do not have Perl in your PATH.
goto endofperl
rem ';
\@perl $opts{ntargs}
\@set ErrorLevel=%ErrorLevel%
\@if NOT "%COMSPEC%" == "%SystemRoot%\\system32\\cmd.exe" \@goto endofperl
\@if %ErrorLevel% == 9009 \@echo You do not have Perl in your PATH.
\@goto endofperl
\@rem ';
EOT

$head =~ s/^\s+//gm;
my $headlines = 2 + ($head =~ tr/\n/\n/);
my $tail = <<'EOT';
__END__
:endofperl
set "ErrorLevel=" & "%COMSPEC%" /d/c exit %ErrorLevel%
@set "ErrorLevel=" & @"%COMSPEC%" /d/c @exit %ErrorLevel%
EOT
$tail =~ s/^\s+//gm;

Expand Down

0 comments on commit 6dd1b61

Please sign in to comment.