@@ -87,90 +87,11 @@ sub make_executable {
8787 }
8888}
8989
90- # This routine was copied almost verbatim from the 'pl2bat' utility
91- # distributed with perl. It requires too much voodoo with shell quoting
92- # differences and shortcomings between the various flavors of Windows
93- # to reliably shell out
9490sub pl2bat {
9591 my $self = shift ;
9692 my %opts = @_ ;
97-
98- # NOTE: %0 is already enclosed in doublequotes by cmd.exe, as appropriate
99- $opts {ntargs } = ' -x -S %0 %*' unless exists $opts {ntargs };
100- $opts {otherargs } = ' -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9' unless exists $opts {otherargs };
101-
102- $opts {stripsuffix } = ' /\\ .plx?/' unless exists $opts {stripsuffix };
103- $opts {stripsuffix } = ($opts {stripsuffix } =~ m { ^/([^/]*[^/\$ ]|)\$ ?/?$} ? $1 : " \Q $opts {stripsuffix}\E " );
104-
105- unless (exists $opts {out }) {
106- $opts {out } = $opts {in };
107- $opts {out } =~ s / $opts{stripsuffix}$// oi ;
108- $opts {out } .= ' .bat' unless $opts {in } =~ / \. bat$ /i or $opts {in } =~ / ^-$ / ;
109- }
110-
111- my $head = <<EOT ;
112- \@ rem = '--*-Perl-*--
113- \@ echo off
114- if "%OS %" == "Windows_NT" goto WinNT
115- perl $opts {otherargs}
116- goto endofperl
117- :WinNT
118- perl $opts {ntargs}
119- if NOT "%COMSPEC %" == "%SystemRoot %\\ system32\\ cmd.exe" goto endofperl
120- if %errorlevel % == 9009 echo You do not have Perl in your PATH.
121- if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
122- goto endofperl
123- \@ rem ';
124- EOT
125-
126- $head =~ s / ^\s +// gm ;
127- my $headlines = 2 + ($head =~ tr / \n/ \n/ );
128- my $tail = " \n __END__\n :endofperl\n " ;
129-
130- my $linedone = 0;
131- my $taildone = 0;
132- my $linenum = 0;
133- my $skiplines = 0;
134-
135- my $start = $Config {startperl };
136- $start = " #!perl" unless $start =~ / ^#!.*perl/ ;
137-
138- open (my $in , ' <' , " $opts {in}" ) or die " Can't open $opts {in}: $! " ;
139- my @file = <$in >;
140- close ($in );
141-
142- foreach my $line ( @file ) {
143- $linenum ++;
144- if ( $line =~ / ^:endofperl\b / ) {
145- if (!exists $opts {update }) {
146- warn " $opts {in} has already been converted to a batch file!\n " ;
147- return ;
148- }
149- $taildone ++;
150- }
151- if ( not $linedone and $line =~ / ^#!.*perl/ ) {
152- if (exists $opts {update }) {
153- $skiplines = $linenum - 1;
154- $line .= " #line " .(1+$headlines )." \n " ;
155- } else {
156- $line .= " #line " .($linenum +$headlines )." \n " ;
157- }
158- $linedone ++;
159- }
160- if ( $line =~ / ^#\s *line\b / and $linenum == 2 + $skiplines ) {
161- $line = " " ;
162- }
163- }
164-
165- open (my $out , ' >' , " $opts {out}" ) or die " Can't open $opts {out}: $! " ;
166- print $out $head ;
167- print $out $start , ( $opts {usewarnings } ? " -w" : " " ),
168- " \n #line " , ($headlines +1), " \n " unless $linedone ;
169- print $out @file [$skiplines ..$#file ];
170- print $out $tail unless $taildone ;
171- close ($out );
172-
173- return $opts {out };
93+ require ExtUtils::PL2Bat;
94+ return ExtUtils::PL2Bat::pl2bat(%opts );
17495}
17596
17697
0 commit comments