| 1 | package ExtUtils::PL2Bat; | ||||||||||||||||||||||||||||
| 2 | 2 | $ExtUtils::PL2Bat::VERSION = '0.004'; | |||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # In core, we can't use any other modules except those that already live in | ||||||||||||||||||||||||||||
| 12 | # lib/, so Exporter is not available to us. | ||||||||||||||||||||||||||||
| 13 | sub import { | ||||||||||||||||||||||||||||
| 14 | 1 | ▶ | my ($self, @functions) = @_; | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | @functions = 'pl2bat' if not @functions; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 1 | my $caller = caller; | |||||||||||||||||||||||||||
| 17 | 1 | for my $function (@functions) { | |||||||||||||||||||||||||||
| 18 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | *{"$caller\::$function"} = \&{$function}; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub pl2bat { | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my %opts = @_; | ||||||||||||||||||||||||||
|
Subroutine
pl2bat: not called CC=21 SCAR=61.4
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # NOTE: %0 is already enclosed in doublequotes by cmd.exe, as appropriate | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | $opts{ntargs} = '-x -S %0 %*' unless exists $opts{ntargs}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $opts{otherargs} = '-x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9' unless exists $opts{otherargs}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $opts{stripsuffix} = qr/\.plx?/ unless exists $opts{stripsuffix}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if (not exists $opts{out}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | $opts{out} = $opts{in}; | |||||||||||||||||||||||||||
| 34 | 0 | $opts{out} =~ s/$opts{stripsuffix}$//i; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | $opts{out} .= '.bat' unless $opts{in} =~ /\.bat$/i or $opts{in} eq '-'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts{"in"} =~ /\.bat$/i or $opts{"in"} eq "-"
MC/DC0%0/2
$opts{"in"} =~ /\.bat$/i or $opts{"in"} eq "-"
$opts{"in"} =~ /\.bat$/i
$opts{"in"} eq "-"
Truth table0%0/3
A or B
A= $opts{"in"} =~ /\.bat$/iB= $opts{"in"} eq "-"
| |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my $head = <<"EOT"; | |||||||||||||||||||||||||||
| 39 | \@rem = '--*-Perl-*-- | ||||||||||||||||||||||||||||
| 40 | \@set "ErrorLevel=" | ||||||||||||||||||||||||||||
| 41 | \@if "%OS%" == "Windows_NT" \@goto WinNT | ||||||||||||||||||||||||||||
| 42 | \@perl $opts{otherargs} | ||||||||||||||||||||||||||||
| 43 | \@set ErrorLevel=%ErrorLevel% | ||||||||||||||||||||||||||||
| 44 | \@goto endofperl | ||||||||||||||||||||||||||||
| 45 | :WinNT | ||||||||||||||||||||||||||||
| 46 | \@perl $opts{ntargs} | ||||||||||||||||||||||||||||
| 47 | \@set ErrorLevel=%ErrorLevel% | ||||||||||||||||||||||||||||
| 48 | \@if NOT "%COMSPEC%" == "%SystemRoot%\\system32\\cmd.exe" \@goto endofperl | ||||||||||||||||||||||||||||
| 49 | \@if %ErrorLevel% == 9009 \@echo You do not have Perl in your PATH. | ||||||||||||||||||||||||||||
| 50 | \@goto endofperl | ||||||||||||||||||||||||||||
| 51 | \@rem '; | ||||||||||||||||||||||||||||
| 52 | EOT | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | $head =~ s/^\s+//gm; | |||||||||||||||||||||||||||
| 55 | 0 | my $headlines = 2 + ($head =~ tr/\n/\n/); | |||||||||||||||||||||||||||
| 56 | 0 | my $tail = <<'EOT'; | |||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||
| 58 | :endofperl | ||||||||||||||||||||||||||||
| 59 | @set "ErrorLevel=" & @goto _undefined_label_ 2>NUL || @"%COMSPEC%" /d/c @exit %ErrorLevel% | ||||||||||||||||||||||||||||
| 60 | EOT | ||||||||||||||||||||||||||||
| 61 | 0 | $tail =~ s/^\s+//gm; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | my $linedone = 0; | |||||||||||||||||||||||||||
| 64 | 0 | my $taildone = 0; | |||||||||||||||||||||||||||
| 65 | 0 | my $linenum = 0; | |||||||||||||||||||||||||||
| 66 | 0 | my $skiplines = 0; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | my $start = $Config{startperl}; | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | $start = '#!perl' unless $start =~ /^#!.*perl/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | open my $in, '<', $opts{in} or croak "Can't open $opts{in}: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | my @file = <$in>; | |||||||||||||||||||||||||||
| 73 | 0 | close $in; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | foreach my $line ( @file ) { | |||||||||||||||||||||||||||
| 76 | 0 | $linenum++; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ( $line =~ /^:endofperl\b/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if (!exists $opts{update}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | warn "$opts{in} has already been converted to a batch file!\n"; | |||||||||||||||||||||||||||
| 80 | 0 | return; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 0 | $taildone++; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ( not $linedone and $line =~ /^#!.*perl/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $linedone and $line =~ /^#!.*perl/
MC/DC0%0/2
not $linedone and $line =~ /^#!.*perl/
not $linedone
$line =~ /^#!.*perl/
Truth table0%0/3
not(A) and B
A= not $linedoneB= $line =~ /^#!.*perl/
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if (exists $opts{update}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | $skiplines = $linenum - 1; | |||||||||||||||||||||||||||
| 87 | 0 | $line .= '#line '.(1+$headlines)."\n"; | |||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||
| 89 | 0 | $line .= '#line '.($linenum+$headlines)."\n"; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 0 | $linedone++; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ( $line =~ /^#\s*line\b/ and $linenum == 2 + $skiplines ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$line =~ /^#\s*line\b/ and $linenum == 2 + $skiplines
MC/DC0%0/2
$line =~ /^#\s*line\b/ and $linenum == 2 + $skiplines
$line =~ /^#\s*line\b/
$linenum == 2 + $skiplines
Truth table0%0/3
A and B
A= $line =~ /^#\s*line\b/B= $linenum == 2 + $skiplines
| |||||||||||||||||||||||||||||
| 94 | 0 | $line = ''; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | open my $out, '>', $opts{out} or croak "Can't open $opts{out}: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | print $out $head; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | print $out $start, ( $opts{usewarnings} ? ' -w' : '' ), | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 101 | "\n#line ", ($headlines+1), "\n" unless $linedone; | ||||||||||||||||||||||||||||
| 102 | 0 | print $out @file[$skiplines..$#file]; | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | print $out $tail unless $taildone; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | close $out; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | return $opts{out}; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 2 | 1; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # ABSTRACT: Batch file creation to run perl scripts on Windows | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||