blib/lib/Module/Build/Platform/Windows.pm

filter: Statementstmt 39.2% 44 / 112 Branchbran 42.0% 21 / 50 Conditioncond 66.6% 10 / 15 MC/DCmcdc 60.0% 6 / 10 Subroutinesub 43.7% 7 / 16 Podpod 0.0% 0 / 7 totaltotal 41.9% 88 / 210 CC 36 SCAR 30.6
CC
36
Cov
42%
_maybe_command
56.0
ACTION_realclean
30.0
make_executable
30.0
CRAP 21.3
« lib/Module/Build/Base.pm ↑ Summary lib/Module/Build/PPMMaker.pm »
1 package Module::Build::Platform::Windows;
2  
3 57 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 57 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 57 our $VERSION = '0.4234';
6 57 $VERSION = eval $VERSION;
7  
8 57 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 57 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 57 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 57 ▶use Module::Build::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 57 our @ISA = qw(Module::Build::Base);
15  
16  
17 0 ▶sub manpage_separator {
Subroutine manpage_separator: not called CC=1 SCAR=6.9
Pod undocumented
18 0 return '.';
19 }
20  
21 0 ▶sub have_forkpipe { 0 }
Subroutine have_forkpipe: not called CC=1 SCAR=6.9
Pod undocumented
22  
23 0 ▶sub _detildefy {
Subroutine _detildefy: not called CC=2 SCAR=17.9
24 0 my ($self, $value) = @_;
25 $value =~ s,^~(?= [/\\] | $ ),$ENV{HOME},x
26 0 ▶ if $ENV{HOME};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"HOME"} 0 0 0
27 0 return $value;
28 }
29  
30 0 ▶sub ACTION_realclean {
Subroutine ACTION_realclean: not called CC=5 SCAR=34.0
Pod undocumented
31 0 my ($self) = @_;
32  
33 0 $self->SUPER::ACTION_realclean();
34  
35 0 my $basename = basename($0);
36 0 $basename =~ s/(?:\.bat)?$//i;
37  
38 0 ▶ if ( lc $basename eq lc $self->build_script ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $basename eq lc $self->build_script) 0 0 0
39 0 ▶ if ( $self->build_bat ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->build_bat) { } 0 0 0
40 0 $self->log_verbose("Deleting $basename.bat\n");
41 0 my $full_progname = $0;
42 0 $full_progname =~ s/(?:\.bat)?$/.bat/i;
43  
44 # Voodoo required to have a batch file delete itself without error;
45 # Syntax differs between 9x & NT: the later requires a null arg (???)
46 0 require Win32;
47 0 ▶ my $null_arg = (Win32::IsWinNT()) ? '""' : '';
Branch: 1 branch
BranchTrueFalseTotal
Win32::IsWinNT() ? : 0 0 0
48 0 my $cmd = qq(start $null_arg /min "\%comspec\%" /c del "$full_progname");
49  
50 0 ▶ open(my $fh, '>>', "$basename.bat")
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">>", "$basename.bat" or die "Can't create $basename.bat: $!" 0 0 0
51 or die "Can't create $basename.bat: $!";
52 0 print $fh $cmd;
53 0 close $fh ;
54 } else {
55 0 $self->delete_filetree($self->build_script . '.bat');
56 }
57 }
58 }
59  
60 0 ▶sub make_executable {
Subroutine make_executable: not called CC=5 SCAR=34.0
Pod undocumented
61 0 my $self = shift;
62  
63 0 $self->SUPER::make_executable(@_);
64  
65 0 foreach my $script (@_) {
66  
67 # Native batch script
68 0 ▶ if ( $script =~ /\.(bat|cmd)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($script =~ /\.(bat|cmd)$/) { } 0 0 0
69 0 $self->SUPER::make_executable($script);
70 0 next;
71  
72 # Perl script that needs to be wrapped in a batch script
73 } else {
74 0 my %opts = ();
75 0 ▶ if ( $script eq $self->build_script ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($script eq $self->build_script) 0 0 0
76 0 $opts{ntargs} = q(-x -S %0 --build_bat %*);
77 0 $opts{otherargs} = q(-x -S "%0" --build_bat %1 %2 %3 %4 %5 %6 %7 %8 %9);
78 }
79  
80 0 my $out = eval {$self->pl2bat(in => $script, update => 1, %opts)};
81 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
82 0 $self->log_warn("WARNING: Unable to convert file '$script' to an executable script:\n$@");
83 } else {
84 0 $self->SUPER::make_executable($out);
85 }
86 }
87 }
88 }
89  
90 0 ▶sub pl2bat {
Subroutine pl2bat: not called CC=1 SCAR=6.9
Pod undocumented
91 0 my $self = shift;
92 0 my %opts = @_;
93 0 require ExtUtils::PL2Bat;
94 0 return ExtUtils::PL2Bat::pl2bat(%opts);
95 }
96  
97  
98 0 ▶sub _quote_args {
Subroutine _quote_args: not called CC=3 SCAR=24.8
99 # Returns a string that can become [part of] a command line with
100 # proper quoting so that the subprocess sees this same list of args.
101 0 my ($self, @args) = @_;
102  
103 0 my @quoted;
104  
105 0 for (@args) {
106 0 ▶ if ( /^[^\s*?!\$<>;|'"\[\]\{\}]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^[^\s*?!\$<>;|'"\[\]\{\}]+$/) { } 0 0 0
107 # Looks pretty safe
108 0 push @quoted, $_;
109 } else {
110 # XXX this will obviously have to improve - is there already a
111 # core module lying around that does proper quoting?
112 0 s/"/\\"/g;
113 0 push @quoted, qq("$_");
114 }
115 }
116  
117 0 return join " ", @quoted;
118 }
119  
120  
121 2850 ▶sub split_like_shell {
Subroutine split_like_shell: called CC=16 SCAR=27.8
Pod undocumented
122 # As it turns out, Windows command-parsing is very different from
123 # Unix command-parsing. Double-quotes mean different things,
124 # backslashes don't necessarily mean escapes, and so on. So we
125 # can't use Text::ParseWords::shellwords() to break a command string
126 # into words. The algorithm below was bashed out by Randy and Ken
127 # (mostly Randy), and there are a lot of regression tests, so we
128 # should feel free to adjust if desired.
129  
130 2850 (my $self, local $_) = @_;
131  
132 2850 ▶ return @$_ if defined() && ref() eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ and ref $_ eq "ARRAY" 57 2793 2850
Condition66%2/3
defined $_ and ref $_ eq "ARRAY"
!ll&&!rl&&r
0279357
MC/DC50%1/2
defined $_ and ref $_ eq "ARRAY"
defined $_ ref $_ eq "ARRAY"
Truth table66%2/3
A and B
A= defined $_B= ref $_ eq "ARRAY"
ABresult
0X0
100
111
133  
134 2793 my @argv;
135 2793 ▶ return @argv unless defined() && length();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ and length $_ 57 2736 2793
Condition66%2/3
defined $_ and length $_
!ll&&!rl&&r
0572736
MC/DC50%1/2
defined $_ and length $_
defined $_ length $_
Truth table66%2/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
136  
137 2736 my $length = length;
138 2736 m/\G\s*/gc;
139  
140 2736 ▶ ARGS: until ( pos == $length ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (pos $_ == $length) 3762 2736 6498
141 3762 my $quote_mode;
142 3762 my $arg = '';
143 3762 ▶ CHARS: until ( pos == $length ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (pos $_ == $length) 16758 2679 19437
144 16758 ▶ if ( m/\G((?:\\\\)+)(?=\\?(")?)/gc ) {
Branch: 5 branches
BranchTrueFalseTotal
if (/\G((?:\\\\)+)(?=\\?(")?)/cg) { } 570 16188 16758
elsif (/\G\\"/cg) { } 912 15276 16188
elsif (/\G"/cg) { } 7239 8037 15276
elsif (not $quote_mode and /\G\s+/cg) { } 1083 6954 8037
elsif (/\G(.)/cgs) { } 6954 0 6954
145 570 ▶ if (defined $2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $2) { } 399 171 570
146 399 $arg .= '\\' x (length($1) / 2);
147 }
148 else {
149 171 $arg .= $1;
150 }
151 }
152 elsif ( m/\G\\"/gc ) {
153 912 $arg .= '"';
154 }
155 elsif ( m/\G"/gc ) {
156 7239 ▶ if ( $quote_mode && m/\G"/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_mode and /\G"/cg) 798 6441 7239
Condition100%3/3
$quote_mode and /\G"/cg
!ll&&!rl&&r
40472394798
MC/DC100%2/2
$quote_mode and /\G"/cg
$quote_mode /\G"/cg
Truth table100%3/3
A and B
A= $quote_modeB= /\G"/cg
ABresult
0X0
100
111
157 798 $arg .= '"';
158 }
159 7239 $quote_mode = !$quote_mode;
160 }
161 ▶ elsif ( !$quote_mode && m/\G\s+/gc ) {
Condition100%3/3
not $quote_mode and /\G\s+/cg
!ll&&!rl&&r
399029641083
MC/DC100%2/2
not $quote_mode and /\G\s+/cg
not $quote_mode /\G\s+/cg
Truth table100%3/3
not(A) and B
A= not $quote_modeB= /\G\s+/cg
ABresult
0X0
100
111
162 1083 last;
163 }
164 elsif ( m/\G(.)/sgc ) {
165 6954 $arg .= $1;
166 }
167 }
168 3762 push @argv, $arg;
169 }
170  
171 2736 return @argv;
172 }
173  
174  
175 # system(@cmd) does not like having double-quotes in it on Windows.
176 # So we quote them and run it as a single command.
177 0 ▶sub do_system {
Subroutine do_system: not called CC=4 SCAR=30.0
Pod undocumented
178 0 my ($self, @cmd) = @_;
179  
180 0 my $cmd = $self->_quote_args(@cmd);
181 0 my $status = system($cmd);
182 0 ▶ if ($status and $! =~ /Argument list too long/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status and $! =~ /Argument list too long/i) 0 0 0
Condition0%0/3
$status and $! =~ /Argument list too long/i
!ll&&!rl&&r
000
MC/DC0%0/2
$status and $! =~ /Argument list too long/i
$status $! =~ /Argument list too long/i
Truth table0%0/3
A and B
A= $statusB= $! =~ /Argument list too long/i
ABresult
0X0
100
111
183 0 my $env_entries = '';
184 0 foreach (sort keys %ENV) { $env_entries .= "$_=>".length($ENV{$_})."; " }
185 0 warn "'Argument list' was 'too long', env lengths are $env_entries";
186 }
187 0 return !$status;
188 }
189  
190 # Copied from ExtUtils::MM_Win32
191 0 ▶sub _maybe_command {
Subroutine _maybe_command: not called CC=7 SCAR=40.3
192 0 my($self,$file) = @_;
193 my @e = exists($ENV{'PATHEXT'})
194 ? split(/;/, $ENV{PATHEXT})
195 0 ▶ : qw(.com .exe .bat .cmd);
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{'PATHEXT'} ? : 0 0 0
196 0 my $e = '';
197 0 for (@e) { $e .= "\Q$_\E|" }
198 0 chop $e;
199 # see if file ends in one of the known extensions
200 0 ▶ if ($file =~ /($e)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /($e)$/i) { } 0 0 0
201 0 ▶ return $file if -e $file;
Branch: 1 branch
BranchTrueFalseTotal
if -e $file 0 0 0
202 }
203 else {
204 0 for (@e) {
205 0 ▶ return "$file$_" if -e "$file$_";
Branch: 1 branch
BranchTrueFalseTotal
if -e "$file$_" 0 0 0
206 }
207 }
208 0 return;
209 }
210  
211  
212 57 1;
213  
214 __END__
« lib/Module/Build/Base.pm ↑ Summary lib/Module/Build/PPMMaker.pm »