blib/lib/Imager/Probe.pm

filter: Statementstmt 7.0% 25 / 356 Branchbran 0.0% 0 / 244 Conditioncond 0.0% 0 / 126 MC/DCmcdc 0.0% 0 / 74 Subroutinesub 20.5% 7 / 34 Podpod 0.0% 0 / 2 totaltotal 3.8% 32 / 836 CC 182 SCAR 58.9
CC
182
Cov
3%
_try_compile_and_link
1056.0
probe
650.0
_probe_check
650.0
CRAP 362.5
« blib/lib/Imager/Font/Wrap.pm ↑ Summary blib/lib/Imager/Preprocess.pm »
1 package Imager::Probe;
2 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = "1.012";
11  
12 1 my @alt_transfer = qw/altname incsuffix libbase/;
13  
14 0 ▶sub probe {
Subroutine probe: not called CC=25 SCAR=64.8
Pod undocumented
15 0 my ($class, $req) = @_;
16  
17 0 _populate_defaults($req);
18  
19 0 my $name = $req->{name};
20 0 my $result;
21 0 ▶ if ($req->{code}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"code"}) 0 0 0
22 0 $result = _probe_code($req);
23 }
24 0 ▶ if (!$result && $req->{pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $result and $req->{"pkg"}) 0 0 0
Condition0%0/3
not $result and $req->{"pkg"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $result and $req->{"pkg"}
not $result $req->{"pkg"}
Truth table0%0/3
not(A) and B
A= not $resultB= $req->{"pkg"}
ABresult
0X0
100
111
25 0 $result = _probe_pkg($req);
26 }
27 0 ▶ if (!$result && $req->{inccheck} && ($req->{libcheck} || $req->{libbase})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $result and $req->{"inccheck"} and $req->{"libcheck"} || $req->{"libbase"}) 0 0 0
Condition0%0/9
not $result and $req->{"inccheck"} and $req->{"libcheck"} || $req->{"libbase"}
!ll&&!rl&&r
000
not $result and $req->{"inccheck"}
!ll&&!rl&&r
000
$req->{"libcheck"} or $req->{"libbase"}
l!l&&r!l&&!r
000
MC/DC0%0/4
not $result and $req->{"inccheck"} and $req->{"libcheck"} || $req->{"libbase"}
not $result $req->{"inccheck"} $req->{"libcheck"} $req->{"libbase"}
Truth table0%0/5
not(A) and B and C or D
A= not $resultB= $req->{"inccheck"}C= $req->{"libcheck"}D= $req->{"libbase"}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
28 0 ▶ $req->{altname} ||= "main";
Condition0%0/2
$req->{"altname"} ||= "main"
l!l
00
MC/DC0%0/1
$req->{"altname"} ||= "main"
$req->{"altname"}
Truth table0%0/2
A
A= $req->{"altname"}
Aresult
11
00
29 0 $result = _probe_check($req);
30 }
31  
32 0 ▶ if ($result && $req->{testcode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result and $req->{"testcode"}) 0 0 0
Condition0%0/3
$result and $req->{"testcode"}
!ll&&!rl&&r
000
MC/DC0%0/2
$result and $req->{"testcode"}
$result $req->{"testcode"}
Truth table0%0/3
A and B
A= $resultB= $req->{"testcode"}
ABresult
0X0
100
111
33 0 $result = _probe_test($req, $result);
34 }
35  
36 0 ▶ if (!$result && $req->{alternatives}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $result and $req->{"alternatives"}) 0 0 0
Condition0%0/3
not $result and $req->{"alternatives"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $result and $req->{"alternatives"}
not $result $req->{"alternatives"}
Truth table0%0/3
not(A) and B
A= not $resultB= $req->{"alternatives"}
ABresult
0X0
100
111
37 0 ALTCHECK:
38 my $index = 1;
39 0 for my $alt (@{$req->{alternatives}}) {
40 0 ▶ $req->{altname} = $alt->{altname} || "alt $index";
Condition0%0/2
$alt->{'altname'} || "alt $index"
l!l
00
MC/DC0%0/1
$alt->{'altname'} || "alt $index"
$alt->{'altname'}
Truth table0%0/2
A
A= $alt->{'altname'}
Aresult
11
00
41 $req->{verbose}
42 0 ▶ and print "$req->{name}: Trying alternative $index\n";
Branch: 1 branch
BranchTrueFalseTotal
$req->{"verbose"} and print qq[$req->{"name"}: Trying alternative $index\n] 0 0 0
43 0 my %work = %$req;
44 0 for my $key (@alt_transfer) {
45 0 ▶ exists $alt->{$key} and $work{$key} = $alt->{$key};
Branch: 1 branch
BranchTrueFalseTotal
exists $alt->{$key} and $work{$key} = $alt->{$key} 0 0 0
46 }
47 0 $result = _probe_check(\%work);
48  
49 0 ▶ if ($result && $req->{testcode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result and $req->{"testcode"}) 0 0 0
Condition0%0/3
$result and $req->{"testcode"}
!ll&&!rl&&r
000
MC/DC0%0/2
$result and $req->{"testcode"}
$result $req->{"testcode"}
Truth table0%0/3
A and B
A= $resultB= $req->{"testcode"}
ABresult
0X0
100
111
50 0 $result = _probe_test(\%work, $result);
51 }
52  
53 $result
54 0 ▶ and last;
Branch: 1 branch
BranchTrueFalseTotal
$result and last 0 0 0
55  
56 0 ++$index;
57 }
58 }
59  
60 0 ▶ if (!$result && $req->{testcode}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $result and $req->{"testcode"}) 0 0 0
Condition0%0/3
not $result and $req->{"testcode"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $result and $req->{"testcode"}
not $result $req->{"testcode"}
Truth table0%0/3
not(A) and B
A= not $resultB= $req->{"testcode"}
ABresult
0X0
100
111
61 0 $result = _probe_fake($req);
62  
63 0 ▶ $result or return;
Branch: 1 branch
BranchTrueFalseTotal
$result or return 0 0 0
64  
65 0 $result = _probe_test($req, $result);
66 }
67  
68 0 ▶ $result or return;
Branch: 1 branch
BranchTrueFalseTotal
$result or return 0 0 0
69  
70 0 return $result;
71 }
72  
73 1 my @default_argv_names =
74 (
75 qw(ccflags optimize cc ldflags)
76 );
77  
78 0 ▶sub _populate_defaults {
Subroutine _populate_defaults: not called CC=4 SCAR=30.0
79 0 my ($req) = @_;
80 0 ▶ $req->{verbose} ||= $ENV{IM_VERBOSE};
Condition0%0/3
$req->{"verbose"} ||= $ENV{"IM_VERBOSE"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->{"verbose"} ||= $ENV{"IM_VERBOSE"}
$req->{"verbose"} $ENV{"IM_VERBOSE"}
Truth table0%0/3
A ||= B
A= $req->{"verbose"}B= $ENV{"IM_VERBOSE"}
ABresult
1X1
011
000
81 0 my %names = map {; $_ => 1 } @default_argv_names;
82 0 @$req{@default_argv_names} = @Config{@default_argv_names};
83 0 for my $arg (@ARGV) {
84 0 ▶ if ($arg =~ /^\U\Q$arg\E=(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^\U\Q$arg\E=(.*)$\E/) 0 0 0
85 0 $req->{$arg} = $1;
86 }
87 }
88 }
89  
90 0 ▶sub _probe_code {
Subroutine _probe_code: not called CC=4 SCAR=30.0
91 0 my ($req) = @_;
92  
93 0 my $code = $req->{code};
94 0 ▶ my @probes = ref $code eq "ARRAY" ? @$code : $code;
Branch: 1 branch
BranchTrueFalseTotal
ref $code eq 'ARRAY' ? : 0 0 0
95  
96 0 my $result;
97 0 for my $probe (@probes) {
98 0 ▶ $result = $probe->($req)
Branch: 1 branch
BranchTrueFalseTotal
$result = &$probe($req) and return $result 0 0 0
99 and return $result;
100 }
101  
102 0 return;
103 }
104  
105 0 ▶sub is_exe {
Subroutine is_exe: not called CC=6 SCAR=37.4
Pod undocumented
106 0 my ($name) = @_;
107  
108 0 my @exe_suffix = $Config{_exe};
109 0 ▶ if ($^O eq 'MSWin32') {
Branch: 2 branches
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
elsif ($^O eq 'cygwin') { } 0 0 0
110 0 push @exe_suffix, qw/.bat .cmd/;
111 }
112 elsif ($^O eq 'cygwin') {
113 0 push @exe_suffix, "";
114 }
115  
116 0 for my $dir (File::Spec->path) {
117 0 for my $suffix (@exe_suffix) {
118 0 ▶ -x File::Spec->catfile($dir, "$name$suffix")
Branch: 1 branch
BranchTrueFalseTotal
-x "File::Spec"->catfile($dir, "$name$suffix") and return 1 0 0 0
119 and return 1;
120 }
121 }
122  
123 0 return;
124 }
125  
126 0 ▶sub _probe_pkg {
Subroutine _probe_pkg: not called CC=16 SCAR=56.1
127 0 my ($req) = @_;
128  
129 # Setup pkg-config's environment variable to search non-standard paths
130 # which may be provided by --libdirs.
131 0 my @pkgcfg_paths = map { "$_/pkgconfig" } _lib_paths( $req );
132 0 ▶ unshift @pkgcfg_paths, $ENV{ 'PKG_CONFIG_PATH' } if $ENV{ 'PKG_CONFIG_PATH' };
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PKG_CONFIG_PATH"} 0 0 0
133  
134 0 local $ENV{ 'PKG_CONFIG_PATH' } = join $Config{path_sep}, @pkgcfg_paths;
135 0 ▶ print "PKG_CONFIG_PATH=$ENV{PKG_CONFIG_PATH}\n" if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
136  
137 0 ▶ is_exe('pkg-config') or return;
Branch: 1 branch
BranchTrueFalseTotal
is_exe("pkg-config") or return 0 0 0
138 0 ▶ my $redir = $^O eq 'MSWin32' ? '' : '2>/dev/null';
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
139  
140 0 my @pkgs = @{$req->{pkg}};
141 0 for my $pkg (@pkgs) {
142 0 ▶ if (!system("pkg-config $pkg --exists $redir")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (system "pkg-config $pkg --exists $redir") 0 0 0
143 # if we find it, but the following fail, then pkg-config is too
144 # broken to be useful
145 0 ▶ my $cflags = `pkg-config $pkg --cflags`
Branch: 1 branch
BranchTrueFalseTotal
my $cflags = `pkg-config $pkg --cflags` and not $? or return 0 0 0
Condition0%0/3
my $cflags = `pkg-config $pkg --cflags` and not $?
!ll&&!rl&&r
000
MC/DC0%0/2
my $cflags = `pkg-config $pkg --cflags` and not $?
my $cflags = `pkg-config $pkg --cflags` not $?
Truth table0%0/3
A and not(B)
A= my $cflags = `pkg-config $pkg --cflags`B= not $?
ABresult
0X0
100
111
146 and !$? or return;
147  
148 0 ▶ my $lflags = `pkg-config $pkg --libs`
Branch: 1 branch
BranchTrueFalseTotal
my $lflags = `pkg-config $pkg --libs` and not $? or return 0 0 0
Condition0%0/3
my $lflags = `pkg-config $pkg --libs` and not $?
!ll&&!rl&&r
000
MC/DC0%0/2
my $lflags = `pkg-config $pkg --libs` and not $?
my $lflags = `pkg-config $pkg --libs` not $?
Truth table0%0/3
A and not(B)
A= my $lflags = `pkg-config $pkg --libs`B= not $?
ABresult
0X0
100
111
149 and !$? or return;
150  
151 0 my $defines = '';
152 0 $cflags =~ s/(-D\S+)/$defines .= " $1"; ''/ge;
153  
154 0 chomp $cflags;
155 0 chomp $lflags;
156 0 print "$req->{name}: Found via pkg-config $pkg\n";
157 0 ▶ print <<EOS if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
158 cflags: $cflags
159 defines: $defines
160 lflags: $lflags
161 EOS
162 # rt 75869
163 # if Win32 doesn't provide this information, too bad
164 0 ▶ if (!grep(/^-L/, split " ", $lflags)
Branch: 1 branch
BranchTrueFalseTotal
if (not grep(/^-L/, split(' ', $lflags, 0)) and $^O ne "MSWin32") 0 0 0
Condition0%0/3
not grep(/^-L/, split(' ', $lflags, 0)) and $^O ne "MSWin32"
!ll&&!rl&&r
000
MC/DC0%0/2
not grep(/^-L/, split(' ', $lflags, 0)) and $^O ne "MSWin32"
not grep(/^-L/, split(' ', $lflags, 0)) $^O ne "MSWin32"
Truth table0%0/3
not(A) and B
A= not grep(/^-L/, split(' ', $lflags, 0))B= $^O ne "MSWin32"
ABresult
0X0
100
111
165 && $^O ne 'MSWin32') {
166 # pkg-config told us about the library, make sure it's
167 # somewhere EU::MM can find it
168 0 ▶ print "Checking if EU::MM can find $lflags\n" if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
169 my ($extra, $bs_load, $ld_load, $ld_run_path) =
170 0 ExtUtils::Liblist->ext($lflags, $req->{verbose});
171 0 ▶ unless ($ld_run_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ld_run_path) 0 0 0
172 # search our standard places
173 0 $lflags = _resolve_libs($req, $lflags);
174 }
175 }
176  
177 return
178 {
179 0 INC => $cflags,
180 LIBS => $lflags,
181 DEFINE => $defines,
182 };
183 }
184 }
185  
186 0 print "$req->{name}: Not found via pkg-config\n";
187  
188 0 return;
189 }
190  
191 0 ▶sub _is_msvc {
Subroutine _is_msvc: not called CC=1 SCAR=6.9
192 0 return $Config{cc} eq "cl";
193 }
194  
195 0 ▶sub _lib_basename {
Subroutine _lib_basename: not called CC=2 SCAR=17.9
196 0 my ($base) = @_;
197  
198 0 ▶ if (_is_msvc()) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_msvc()) { } 0 0 0
199 0 return $base;
200 }
201 else {
202 0 return "lib$base";
203 }
204 }
205  
206 0 ▶sub _lib_option {
Subroutine _lib_option: not called CC=2 SCAR=17.9
207 0 my ($base) = @_;
208  
209 0 ▶ if (_is_msvc()) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_msvc()) { } 0 0 0
210 0 return $base . $Config{_a};
211 }
212 else {
213 0 return "-l$base";
214 }
215 }
216  
217 0 ▶sub _quotearg {
Subroutine _quotearg: not called CC=2 SCAR=17.9
218 0 my ($opt) = @_;
219  
220 0 ▶ return $opt =~ /\s/ ? qq("$opt") : $opt;
Branch: 1 branch
BranchTrueFalseTotal
$opt =~ /\s/ ? : 0 0 0
221 }
222  
223 0 ▶sub _probe_check {
Subroutine _probe_check: not called CC=25 SCAR=64.8
224 0 my ($req) = @_;
225  
226 0 my @libcheck;
227 my @libbase;
228 0 ▶ if ($req->{libcheck}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($req->{'libcheck'}) { } 0 0 0
elsif ($req->{'libbase'}) { } 0 0 0
229 0 ▶ if (ref $req->{libcheck} eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $req->{'libcheck'} eq 'ARRAY') { } 0 0 0
230 0 push @libcheck, @{$req->{libcheck}};
231 }
232 else {
233 0 push @libcheck, $req->{libcheck};
234 }
235 }
236 elsif ($req->{libbase}) {
237 0 ▶ @libbase = ref $req->{libbase} ? @{$req->{libbase}} : $req->{libbase};
Branch: 1 branch
BranchTrueFalseTotal
ref $req->{'libbase'} ? : 0 0 0
238  
239 0 my $lext=$Config{'so'}; # Get extensions of libraries
240 0 my $aext=$Config{'_a'};
241  
242 0 for my $libbase (@libbase) {
243 0 my $basename = _lib_basename($libbase);
244 0 ▶ push @libcheck, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
245 0 ▶ -e File::Spec->catfile($_[0], "$basename$aext")
Branch: 1 branch
BranchTrueFalseTotal
-e "File::Spec"->catfile($_[0], "$basename$aext") or -e "File::Spec"->catfile($_[0], "$basename.$lext") 0 0 0
246 || -e File::Spec->catfile($_[0], "$basename.$lext")
247 0 };
248 }
249 }
250 else {
251 print "$req->{name}: No libcheck or libbase, nothing to search for\n"
252 0 ▶ if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
253 0 return;
254 }
255  
256 0 my @found_libpath;
257 0 my @lib_search = _lib_paths($req);
258 print "$req->{name}: Searching directories for libraries:\n"
259 0 ▶ if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
260 0 for my $libcheck (@libcheck) {
261 0 for my $path (@lib_search) {
262 0 ▶ print "$req->{name}: $path\n" if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
263 0 ▶ if ($libcheck->($path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$libcheck($path)) 0 0 0
264 0 ▶ print "$req->{name}: Found!\n" if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
265 0 push @found_libpath, $path;
266 0 last;
267 }
268 }
269 }
270  
271 0 my $found_incpath;
272 0 my $inccheck = $req->{inccheck};
273 0 my @inc_search = _inc_paths($req);
274 print "$req->{name}: Searching directories for headers:\n"
275 0 ▶ if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
276 0 for my $path (@inc_search) {
277 0 ▶ print "$req->{name}: $path\n" if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
278 0 ▶ if ($inccheck->($path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$inccheck($path)) 0 0 0
279 0 ▶ print "$req->{name}: Found!\n" if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
280 0 $found_incpath = $path;
281 0 last;
282 }
283 }
284  
285 0 my $alt = "";
286 0 ▶ if ($req->{altname}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"altname"}) 0 0 0
287 0 $alt = " $req->{altname}:";
288 }
289 0 ▶ print "$req->{name}:$alt includes ", $found_incpath ? "" : "not ",
Branch: 2 branches
BranchTrueFalseTotal
$found_incpath ? : 0 0 0
@found_libpath == @libcheck ? : 0 0 0
290 "found - libraries ", @found_libpath == @libcheck ? "" : "not ", "found\n";
291  
292 0 ▶ @found_libpath == @libcheck && $found_incpath
Branch: 1 branch
BranchTrueFalseTotal
@found_libpath == @libcheck and $found_incpath or return 0 0 0
Condition0%0/3
@found_libpath == @libcheck and $found_incpath
!ll&&!rl&&r
000
MC/DC0%0/2
@found_libpath == @libcheck and $found_incpath
@found_libpath == @libcheck $found_incpath
Truth table0%0/3
A and B
A= @found_libpath == @libcheckB= $found_incpath
ABresult
0X0
100
111
293 or return;
294  
295 0 my @libs = map "-L$_", @found_libpath;
296 0 ▶ if ($req->{libopts}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($req->{'libopts'}) { } 0 0 0
elsif (@libbase) { } 0 0 0
297 0 push @libs, $req->{libopts};
298 }
299 elsif (@libbase) {
300 0 push @libs, map _lib_option($_), @libbase;
301 }
302 else {
303 0 die "$req->{altname}: inccheck but no libbase or libopts";
304 }
305  
306 return
307 {
308 0 INC => _quotearg("-I$found_incpath"),
309 LIBS => join(" ", map _quotearg($_), @libs),
310 DEFINE => "",
311 };
312 }
313  
314 0 ▶sub _probe_fake {
Subroutine _probe_fake: not called CC=7 SCAR=40.3
315 0 my ($req) = @_;
316  
317 # the caller provided test code, and the compiler may look in
318 # places we don't, see Imager-Screenshot ticket 56793,
319 # so fake up a result so the test code can
320 0 my $lopts;
321 0 ▶ if ($req->{libopts}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($req->{'libopts'}) { } 0 0 0
elsif (defined $req->{'libbase'}) { } 0 0 0
322 0 $lopts = $req->{libopts};
323 }
324 elsif (defined $req->{libbase}) {
325 # might not need extra libraries, eg. Win32 perl already links
326 # everything
327 my @libs = $req->{libbase}
328 0 ? ( ref $req->{libbase} ? @{$req->{libbase}} : $req->{libbase} )
329 0 ▶ : ();
Branch: 2 branches
BranchTrueFalseTotal
$req->{'libbase'} ? : 0 0 0
ref $req->{'libbase'} ? : 0 0 0
330 0 $lopts = join " ", map _lib_option($_), @libs;
331 }
332 0 ▶ if (defined $lopts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lopts) { } 0 0 0
333 0 print "$req->{name}: Checking if the compiler can find them on its own\n";
334 return
335 {
336 0 INC => "",
337 LIBS => $lopts,
338 DEFINE => "",
339 };
340 }
341 else {
342 print "$req->{name}: Can't fake it - no libbase or libopts\n"
343 0 ▶ if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
344 0 return;
345 }
346 }
347  
348 0 ▶sub _probe_test {
Subroutine _probe_test: not called CC=7 SCAR=40.3
349 0 my ($req, $result) = @_;
350  
351 # setup LD_RUN_PATH to match link time
352 0 ▶ print "Asking liblist for LD_RUN_PATH:\n" if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
353 my ($extra, $bs_load, $ld_load, $ld_run_path) =
354 0 ExtUtils::Liblist->ext($result->{LIBS}, $req->{verbose});
355 0 local $ENV{LD_RUN_PATH};
356  
357 0 ▶ if ($ld_run_path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ld_run_path) 0 0 0
358 print "Setting LD_RUN_PATH=$ld_run_path for $req->{name} probe\n"
359 0 ▶ if $req->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} 0 0 0
360 0 $ENV{LD_RUN_PATH} = $ld_run_path;
361 0 ▶ if ($Config{lddlflags} =~ /([^ ]*-(?:rpath|R)[,=]?)([^ ]+)/
Branch: 1 branch
BranchTrueFalseTotal
if ($Imager::Probe::Config{"lddlflags"} =~ /([^ ]*-(?:rpath|R)[,=]?)([^ ]+)/ and -d $2) 0 0 0
Condition0%0/3
$Imager::Probe::Config{"lddlflags"} =~ /([^ ]*-(?:rpath|R)[,=]?)([^ ]+)/ and -d $2
!ll&&!rl&&r
000
MC/DC0%0/2
$Imager::Probe::Config{"lddlflags"} =~ /([^ ]*-(?:rpath|R)[,=]?)([^ ]+)/ and -d $2
$Imager::Probe::Config{"lddlflags"} =~ /([^ ]*-(?:rpath|R)[,=]?)([^ ]+)/ -d $2
Truth table0%0/3
A and B
A= $Imager::Probe::Config{"lddlflags"} =~ /([^ ]*-(?:rpath|R)[,=]?)([^ ]+)/B= -d $2
ABresult
0X0
100
111
362 && -d $2) {
363 # hackety, hackety
364 # LD_RUN_PATH is ignored when there's already an -rpath option
365 # so provide one
366 0 my $prefix = $1;
367 $result->{LDDLFLAGS} = $Config{lddlflags} . " " .
368 0 join " ", map "$prefix$_", split $Config{path_sep}, $ld_run_path;
369 }
370 }
371 my $good = _check_lib(
372 $req,
373 LIBS => $result->{LIBS},
374 INC => $result->{INC},
375 header => $req->{testcodeheaders},
376 function => $req->{testcode},
377 prologue => $req->{testcodeprologue},
378 0 );
379 0 ▶ unless ($good) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($good) 0 0 0
380 0 print "$req->{name}: Test code failed: $@";
381 0 return;
382 }
383  
384 0 print "$req->{name}: Passed code check\n";
385 0 return $result;
386 }
387  
388 0 ▶sub _check_lib {
Subroutine _check_lib: not called CC=6 SCAR=37.4
389 0 my ($req, %args) = @_;
390  
391 0 my $code = "";
392 0 ▶ if (my $hdrs = $args{header}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hdrs = $args{"header"}) 0 0 0
393 0 ▶ ref $hdrs or $hdrs = [ $hdrs ];
Branch: 1 branch
BranchTrueFalseTotal
ref $hdrs or $hdrs = [$hdrs] 0 0 0
394 0 $code .= "#include <$_>\n" for @$hdrs;
395 }
396 0 ▶ $code .= $args{prologue} if $args{prologue};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"prologue"} 0 0 0
397 0 ▶ $args{function} or Carp::confess "Missing function";
Branch: 1 branch
BranchTrueFalseTotal
$args{"function"} or Carp::confess("Missing function") 0 0 0
398 0 $code .= "int main(int argc, char **argv) {\n$args{function}\n}\n";
399  
400 return _try_compile_and_link
401 (
402 $code, $req,
403 name => $req->{name},
404 ccflags => $args{INC},
405 run => 1,
406 libs => $args{LIBS},
407 0 );
408 }
409  
410 0 ▶sub _resolve_libs {
Subroutine _resolve_libs: not called CC=5 SCAR=34.0
411 0 my ($req, $lflags) = @_;
412  
413 0 my @libs = grep /^-l/, split ' ', $lflags;
414 0 my %paths;
415 0 my @paths = _lib_paths($req);
416 0 my $so = $Config{so};
417 0 my $libext = $Config{_a};
418 0 for my $lib (@libs) {
419 0 $lib =~ s/^-l/lib/;
420  
421 0 for my $path (@paths) {
422 0 ▶ if (-e "$path/$lib.$so" || -e "$path/$lib$libext") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$path/$lib.$so" or -e "$path/$lib$libext") 0 0 0
Condition0%0/3
-e "$path/$lib.$so" or -e "$path/$lib$libext"
l!l&&r!l&&!r
000
MC/DC0%0/2
-e "$path/$lib.$so" or -e "$path/$lib$libext"
-e "$path/$lib.$so" -e "$path/$lib$libext"
Truth table0%0/3
A or B
A= -e "$path/$lib.$so"B= -e "$path/$lib$libext"
ABresult
1X1
011
000
423 0 $paths{$path} = 1;
424 }
425 }
426 }
427  
428 0 return join(" ", ( map "-L$_", keys %paths ), $lflags );
429 }
430  
431 0 ▶sub _lib_paths {
Subroutine _lib_paths: not called CC=11 SCAR=48.8
432 0 my ($req) = @_;
433  
434 print "$req->{name} IM_LIBPATH: $ENV{IM_LIBPATH}\n"
435 0 ▶ if $req->{verbose} && defined $ENV{IM_LIBPATH};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} and defined $ENV{"IM_LIBPATH"} 0 0 0
Condition0%0/3
$req->{"verbose"} and defined $ENV{"IM_LIBPATH"}
!ll&&!rl&&r
000
MC/DC0%0/2
$req->{"verbose"} and defined $ENV{"IM_LIBPATH"}
$req->{"verbose"} defined $ENV{"IM_LIBPATH"}
Truth table0%0/3
A and B
A= $req->{"verbose"}B= defined $ENV{"IM_LIBPATH"}
ABresult
0X0
100
111
436 print "$req->{name} LIB: $ENV{IM_LIBPATH}\n"
437 0 ▶ if $req->{verbose} && defined $ENV{LIB} && $^O eq "MSWin32";
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} and defined $ENV{"LIB"} and $^O eq "MSWin32" 0 0 0
Condition0%0/6
$req->{"verbose"} and defined $ENV{"LIB"} and $^O eq "MSWin32"
!ll&&!rl&&r
000
$req->{"verbose"} and defined $ENV{"LIB"}
!ll&&!rl&&r
000
MC/DC0%0/3
$req->{"verbose"} and defined $ENV{"LIB"} and $^O eq "MSWin32"
$req->{"verbose"} defined $ENV{"LIB"} $^O eq "MSWin32"
Truth table0%0/4
A and B and C
A= $req->{"verbose"}B= defined $ENV{"LIB"}C= $^O eq "MSWin32"
ABCresult
0XX0
10X0
1100
1111
438 0 my $lp = $req->{libpath};
439 print "$req->{name} libpath: ", ref $lp ? join($Config{path_sep}, @$lp) : $lp, "\n"
440 0 ▶ if $req->{verbose} && defined $lp;
Branch: 2 branches
BranchTrueFalseTotal
if $req->{"verbose"} and defined $lp 0 0 0
ref $lp ? : 0 0 0
Condition0%0/3
$req->{"verbose"} and defined $lp
!ll&&!rl&&r
000
MC/DC0%0/2
$req->{"verbose"} and defined $lp
$req->{"verbose"} defined $lp
Truth table0%0/3
A and B
A= $req->{"verbose"}B= defined $lp
ABresult
0X0
100
111
441  
442 return _paths
443 (
444 $ENV{IM_LIBPATH},
445 $req->{libpath},
446 (
447 0 ▶ map { split ' ' }
Branch: 2 branches
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
$^O eq 'cygwin' ? : 0 0 0
448 grep $_,
449 @Config{qw/loclibpth libpth libspath/}
450 ),
451 0 $^O eq "MSWin32" ? $ENV{LIB} : "",
452 $^O eq "cygwin" ? "/usr/lib/w32api" : "",
453 "/usr/lib",
454 "/usr/local/lib",
455 _gcc_lib_paths(),
456 _dyn_lib_paths(),
457 );
458 }
459  
460 0 ▶sub _gcc_lib_paths {
Subroutine _gcc_lib_paths: not called CC=6 SCAR=37.4
461 $Config{gccversion}
462 0 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$Imager::Probe::Config{"gccversion"} or return 0 0 0
463  
464 0 ▶ my ($base_version) = $Config{gccversion} =~ /^([0-9]+)/
Branch: 1 branch
BranchTrueFalseTotal
my($base_version) = $Imager::Probe::Config{"gccversion"} =~ /^([0-9]+)/ or return 0 0 0
465 or return;
466  
467 0 ▶ $base_version >= 4
Branch: 1 branch
BranchTrueFalseTotal
$base_version >= 4 or return 0 0 0
468 or return;
469  
470 0 local $ENV{LANG} = "C";
471 0 local $ENV{LC_ALL} = "C";
472 0 ▶ my ($lib_line) = grep /^libraries:/, `$Config{cc} -print-search-dirs`
Branch: 1 branch
BranchTrueFalseTotal
my($lib_line) = grep(/^libraries:/, `$Imager::Probe::Config{"cc"} -print-search-dirs`) or return 0 0 0
473 or return;
474 0 $lib_line =~ s/^libraries: =//;
475 0 chomp $lib_line;
476  
477 0 ▶ return grep !/gcc/ && -d, split /:/, $lib_line;
Condition0%0/3
!/gcc/ && -d $_
!ll&&!rl&&r
000
MC/DC0%0/2
!/gcc/ && -d $_
!/gcc/ -d $_
Truth table0%0/3
not(A) && B
A= !/gcc/B= -d $_
ABresult
0X0
100
111
478 }
479  
480 0 ▶sub _dyn_lib_paths {
Subroutine _dyn_lib_paths: not called CC=2 SCAR=17.9
481 0 ▶ return map { defined() ? split /\Q$Config{path_sep}/ : () }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
482 0 map $ENV{$_},
483 qw(LD_RUN_PATH LD_LIBRARY_PATH DYLD_LIBRARY_PATH LIBRARY_PATH);
484 }
485  
486 0 ▶sub _inc_paths {
Subroutine _inc_paths: not called CC=12 SCAR=50.5
487 0 my ($req) = @_;
488  
489 print "$req->{name} IM_INCPATH: $ENV{IM_INCPATH}\n"
490 0 ▶ if $req->{verbose} && defined $ENV{IM_INCPATH};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} and defined $ENV{"IM_INCPATH"} 0 0 0
Condition0%0/3
$req->{"verbose"} and defined $ENV{"IM_INCPATH"}
!ll&&!rl&&r
000
MC/DC0%0/2
$req->{"verbose"} and defined $ENV{"IM_INCPATH"}
$req->{"verbose"} defined $ENV{"IM_INCPATH"}
Truth table0%0/3
A and B
A= $req->{"verbose"}B= defined $ENV{"IM_INCPATH"}
ABresult
0X0
100
111
491 print "$req->{name} INCLUDE: $ENV{INCLUDE}\n"
492 0 ▶ if $req->{verbose} && defined $ENV{INCLUDE} && $^O eq "MSWin32";
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"verbose"} and defined $ENV{"INCLUDE"} and $^O eq "MSWin32" 0 0 0
Condition0%0/6
$req->{"verbose"} and defined $ENV{"INCLUDE"} and $^O eq "MSWin32"
!ll&&!rl&&r
000
$req->{"verbose"} and defined $ENV{"INCLUDE"}
!ll&&!rl&&r
000
MC/DC0%0/3
$req->{"verbose"} and defined $ENV{"INCLUDE"} and $^O eq "MSWin32"
$req->{"verbose"} defined $ENV{"INCLUDE"} $^O eq "MSWin32"
Truth table0%0/4
A and B and C
A= $req->{"verbose"}B= defined $ENV{"INCLUDE"}C= $^O eq "MSWin32"
ABCresult
0XX0
10X0
1100
1111
493 0 my $ip = $req->{incpath};
494 print "$req->{name} incpath: ", ref $ip ? join($Config{path_sep}, @$ip) : $ip, "\n"
495 0 ▶ if $req->{verbose} && defined $req->{incpath};
Branch: 2 branches
BranchTrueFalseTotal
if $req->{"verbose"} and defined $req->{"incpath"} 0 0 0
ref $ip ? : 0 0 0
Condition0%0/3
$req->{"verbose"} and defined $req->{"incpath"}
!ll&&!rl&&r
000
MC/DC0%0/2
$req->{"verbose"} and defined $req->{"incpath"}
$req->{"verbose"} defined $req->{"incpath"}
Truth table0%0/3
A and B
A= $req->{"verbose"}B= defined $req->{"incpath"}
ABresult
0X0
100
111
496  
497 my @paths = _paths
498 (
499 $ENV{IM_INCPATH},
500 $req->{incpath},
501 $^O eq "MSWin32" ? $ENV{INCLUDE} : "",
502 $^O eq "cygwin" ? "/usr/include/w32api" : "",
503 (
504 0 map { split ' ' }
505 grep $_,
506 0 ▶ @Config{qw/locincpth incpath/}
Branch: 2 branches
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
$^O eq 'cygwin' ? : 0 0 0
507 ),
508 "/usr/include",
509 "/usr/local/include",
510 _gcc_inc_paths(),
511 _dyn_inc_paths(),
512 );
513  
514 0 ▶ if ($req->{incsuffix}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"incsuffix"}) 0 0 0
515 0 @paths = map File::Spec->catdir($_, $req->{incsuffix}), @paths;
516 }
517  
518 0 return @paths;
519 }
520  
521 0 ▶sub _gcc_inc_paths {
Subroutine _gcc_inc_paths: not called CC=10 SCAR=47.0
522 $Config{gccversion}
523 0 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$Imager::Probe::Config{"gccversion"} or return 0 0 0
524  
525 0 ▶ my ($base_version) = $Config{gccversion} =~ /^([0-9]+)/
Branch: 1 branch
BranchTrueFalseTotal
my($base_version) = $Imager::Probe::Config{"gccversion"} =~ /^([0-9]+)/ or return 0 0 0
526 or return;
527  
528 0 ▶ $base_version >= 4
Branch: 1 branch
BranchTrueFalseTotal
$base_version >= 4 or return 0 0 0
529 or return;
530  
531 0 local $ENV{LANG} = "C";
532 0 local $ENV{LC_ALL} = "C";
533 0 my $devnull = File::Spec->devnull;
534 0 my @spam = `$Config{cc} -E -v - <$devnull 2>&1`;
535 # output includes lines like:
536 # ...
537 # ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../x86_64-linux-gnu/include"
538 # #include "..." search starts here:
539 # #include <...> search starts here:
540 # /usr/lib/gcc/x86_64-linux-gnu/4.9/include
541 # /usr/local/include
542 # /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed
543 # /usr/include/x86_64-linux-gnu
544 # /usr/include
545 # End of search list.
546 # # 1 "<stdin>"
547 # # 1 "<built-in>"
548 # ...
549  
550 0 ▶ while (@spam && $spam[0] !~ /^#include /) {
Branch: 1 branch
BranchTrueFalseTotal
if (@spam and not $spam[0] =~ /^#include /) 0 0 0
Condition0%0/3
@spam and not $spam[0] =~ /^#include /
!ll&&!rl&&r
000
MC/DC0%0/2
@spam and not $spam[0] =~ /^#include /
@spam not $spam[0] =~ /^#include /
Truth table0%0/3
A and not(B)
A= @spamB= not $spam[0] =~ /^#include /
ABresult
0X0
100
111
551 0 shift @spam;
552 }
553 0 my @inc;
554 0 ▶ while (@spam && $spam[0] !~ /^End of search/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@spam and not $spam[0] =~ /^End of search/) 0 0 0
Condition0%0/3
@spam and not $spam[0] =~ /^End of search/
!ll&&!rl&&r
000
MC/DC0%0/2
@spam and not $spam[0] =~ /^End of search/
@spam not $spam[0] =~ /^End of search/
Truth table0%0/3
A and not(B)
A= @spamB= not $spam[0] =~ /^End of search/
ABresult
0X0
100
111
555 0 my $line = shift @spam;
556 0 chomp $line;
557 0 ▶ next if $line =~ /^#include /;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#include / 0 0 0
558 0 ▶ next unless $line =~ s/^\s+//;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ s/^\s+// 0 0 0
559 0 push @inc, $line;
560 }
561 0 return @inc;
562 }
563  
564 0 ▶sub _dyn_inc_paths {
Subroutine _dyn_inc_paths: not called CC=2 SCAR=17.9
565 return map {
566 0 my $tmp = $_;
567 0 ▶ $tmp =~ s/\blib$/include/ ? $tmp : ()
Branch: 1 branch
BranchTrueFalseTotal
$tmp =~ s/\blib$/include/ ? : 0 0 0
568 } _dyn_lib_paths();
569 }
570  
571 0 ▶sub _paths {
Subroutine _paths: not called CC=4 SCAR=30.0
572 0 my (@in) = @_;
573  
574 0 my @out;
575  
576 # expand any array refs
577 0 ▶ @in = map { ref() ? @$_ : $_ } @in;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
578  
579 0 for my $path (@in) {
580 0 ▶ $path or next;
Branch: 1 branch
BranchTrueFalseTotal
$path or next 0 0 0
581 0 $path = _tilde_expand($path);
582  
583 0 push @out, grep -d $_, split /\Q$Config{path_sep}/, $path;
584 }
585  
586 0 @out = map Cwd::realpath($_), @out;
587  
588 0 my %seen;
589 0 @out = grep !$seen{$_}++, @out;
590  
591 0 return @out;
592 }
593  
594 1 my $home;
595 0 ▶sub _tilde_expand {
Subroutine _tilde_expand: not called CC=9 SCAR=45.0
596 0 my ($path) = @_;
597  
598 0 ▶ if ($path =~ m!^~[/\\]!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m(^~[/\\])) 0 0 0
599 0 ▶ defined $home or $home = $ENV{HOME};
Branch: 1 branch
BranchTrueFalseTotal
defined $home or $home = $ENV{"HOME"} 0 0 0
600 0 ▶ if (!defined $home && $^O eq 'MSWin32'
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $home and $^O eq "MSWin32" and defined $ENV{"HOMEDRIVE"} and defined $ENV{"HOMEPATH"}) 0 0 0
Condition0%0/9
not defined $home and $^O eq "MSWin32" and defined $ENV{"HOMEDRIVE"} and defined $ENV{"HOMEPATH"}
!ll&&!rl&&r
000
not defined $home and $^O eq "MSWin32" and defined $ENV{"HOMEDRIVE"}
!ll&&!rl&&r
000
not defined $home and $^O eq "MSWin32"
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $home and $^O eq "MSWin32" and defined $ENV{"HOMEDRIVE"} and defined $ENV{"HOMEPATH"}
not defined $home $^O eq "MSWin32" defined $ENV{"HOMEDRIVE"} defined $ENV{"HOMEPATH"}
Truth table0%0/5
not(A) and B and C and D
A= not defined $homeB= $^O eq "MSWin32"C= defined $ENV{"HOMEDRIVE"}D= defined $ENV{"HOMEPATH"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
601 && defined $ENV{HOMEDRIVE} && defined $ENV{HOMEPATH}) {
602 0 $home = $ENV{HOMEDRIVE} . $ENV{HOMEPATH};
603 }
604 0 ▶ unless (defined $home) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $home) 0 0 0
605 0 $home = eval { (getpwuid($<))[7] };
606 }
607 0 ▶ defined $home or die "You supplied $path, but I can't find your home directory\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $home or die "You supplied $path, but I can't find your home directory\n" 0 0 0
608 0 $path =~ s/^~//;
609 0 $path = File::Spec->catdir($home, $path);
610 }
611  
612 0 return $path;
613 }
614  
615 0 ▶sub _tcal_state {
Subroutine _tcal_state: not called CC=3 SCAR=24.8
616 0 my ($req) = @_;
617 0 my %state;
618  
619 0 ▶ $state{start_dir} = Cwd::getcwd()
Branch: 1 branch
BranchTrueFalseTotal
$state{"start_dir"} = Cwd::getcwd() or die "Cannot save current directory: $!\n" 0 0 0
620 or die "Cannot save current directory: $!\n";
621 0 $state{keep} = !!$ENV{IMAGER_PROBE_KEEP_FILES};
622 $state{tmpdir} = File::Temp->newdir(CLEANUP => !$state{keep})
623 0 ▶ or Carp::confess("panic: cannot create temp directory");
Branch: 1 branch
BranchTrueFalseTotal
$state{"tmpdir"} = "File::Temp"->newdir("CLEANUP", !$state{"keep"}) or Carp::confess("panic: cannot create temp directory") 0 0 0
624 0 $state{num} = 1;
625  
626 0 \%state;
627 }
628  
629 0 ▶sub _sort_std {
Subroutine _sort_std: not called CC=1 SCAR=6.9
630 0 my @stds = grep defined, @_;
631 # we don't support -std=iso9899:1999 etc
632 0 ▶ my $std_map = sub { my $std = shift; return $std > 80 ? $std-100 : $std };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$std > 80 ? : 0 0 0
633 0 return sort { $std_map->($b) <=> $std_map->($a) } grep defined, @stds;
634 }
635  
636 # _try_compile_and_link
637 # adapted from Time::HiRes and then adapted some more.
638 # This is not part of the Imager::Probe API
639 #
640 # $code - code to test
641 #
642 # %args - options to control this test
643 # name - required description of what we're testing, used for verbose
644 # cc - optional C compiler (overrides $req->{cc}
645 # ccflags - optional extra compiler flags
646 # ccflags_only - only use ccflags and don't use $req->{ccflags}
647 # libs - extra libraries to link to
648 # std - C standard, needs stdflag set in $req per by probe_std()
649 # nolink - only test compilation success
650 #
651 # $req contains probing state, used here:
652 # verbose - print messages if true
653 # stdflag - compiler option used to select a C standard, by probe_std
654 # minstd - minimum standard (default: 99)
655 # ccflags - base ccflags
656 # cc - base cc
657 #
658  
659 0 ▶sub _try_compile_and_link {
Subroutine _try_compile_and_link: not called CC=32 SCAR=69.6
660 0 my ($code, $req, %args) = @_;
661  
662 0 ▶ my $verbose = $req->{verbose} || 0;
Condition0%0/2
$req->{'verbose'} || 0
l!l
00
MC/DC0%0/1
$req->{'verbose'} || 0
$req->{'verbose'}
Truth table0%0/2
A
A= $req->{'verbose'}
Aresult
11
00
663 0 ▶ my $indent = $req->{indent} || "";
Condition0%0/2
$req->{'indent'} || ''
l!l
00
MC/DC0%0/1
$req->{'indent'} || ''
$req->{'indent'}
Truth table0%0/2
A
A= $req->{'indent'}
Aresult
11
00
664 my $name = $args{name}
665 0 ▶ or Carp::confess("panic: no name supplied to _try_compile_and_link");
Branch: 1 branch
BranchTrueFalseTotal
my $name = $args{"name"} or Carp::confess("panic: no name supplied to _try_compile_and_link") 0 0 0
666 0 ▶ my $state = $req->{tcal_state} ||= _tcal_state($req);
Condition0%0/3
$req->{"tcal_state"} ||= _tcal_state($req)
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->{"tcal_state"} ||= _tcal_state($req)
$req->{"tcal_state"} _tcal_state($req)
Truth table0%0/3
A ||= B
A= $req->{"tcal_state"}B= _tcal_state($req)
ABresult
1X1
011
000
667 chdir $state->{tmpdir}
668 0 ▶ or die "Cannot chdir to $state->{tmpdir}: $!";
Branch: 1 branch
BranchTrueFalseTotal
chdir $state->{"tmpdir"} or die qq[Cannot chdir to $state->{"tmpdir"}: $!] 0 0 0
669 0 my $ok = 0;
670 0 my $base = "test$state->{num}";
671 0 ++$state->{num};
672  
673 0 ▶ my $obj_ext = $Config{obj_ext} || ".o";
Condition0%0/2
$Imager::Probe::Config{'obj_ext'} || '.o'
l!l
00
MC/DC0%0/1
$Imager::Probe::Config{'obj_ext'} || '.o'
$Imager::Probe::Config{'obj_ext'}
Truth table0%0/2
A
A= $Imager::Probe::Config{'obj_ext'}
Aresult
11
00
674 0 unlink("$base.c", "$base$obj_ext");
675  
676 0 ▶ if (open(my $tmpc, '>', "$base.c")) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $tmpc, ">", "$base.c") 0 0 0
677 0 print $tmpc $code;
678 0 close($tmpc);
679  
680 # we don't need this for our probes
681 #my $COREincdir = File::Spec->catdir($Config{'archlibexp'}, 'CORE');
682  
683 0 my $cc = $req->{cc};
684 0 my $ccflags = "";
685 0 ▶ $ccflags = $req->{ccflags} unless $args{ccflags_only};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"ccflags_only"} 0 0 0
686 0 ▶ $ccflags .= " $args{ccflags}" if $args{ccflags};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"ccflags"} 0 0 0
687 0 $ccflags .= " $req->{'optimize'}";
688 # we want the maximum std
689 0 my ($std) = _sort_std($args{std}, $req->{minstd});
690 0 ▶ my $stdflag = $args{stdflag} || $req->{stdflag};
Condition0%0/3
$args{'stdflag'} || $req->{'stdflag'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'stdflag'} || $req->{'stdflag'}
$args{'stdflag'} $req->{'stdflag'}
Truth table0%0/3
A || B
A= $args{'stdflag'}B= $req->{'stdflag'}
ABresult
1X1
011
000
691 0 ▶ if ($std && $stdflag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($std and $stdflag) 0 0 0
Condition0%0/3
$std and $stdflag
!ll&&!rl&&r
000
MC/DC0%0/2
$std and $stdflag
$std $stdflag
Truth table0%0/3
A and B
A= $stdB= $stdflag
ABresult
0X0
100
111
692 0 $ccflags .= " $stdflag$std";
693 }
694 # we don't need this (yet)
695 #. ' ' . "-I$COREincdir" . ' -DPERL_NO_INLINE_FUNCTIONS';
696  
697 0 ▶ my $errornull = $verbose ? '' : "2>" . File::Spec->devnull;
Branch: 1 branch
BranchTrueFalseTotal
$verbose ? : 0 0 0
698  
699 0 my $cccmd;
700 my $base_out;
701 0 ▶ if ($args{nolink}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'nolink'}) { } 0 0 0
702 0 $base_out = "$base$obj_ext";
703 0 $cccmd = "$cc -c -o $base_out $ccflags $base.c $errornull";
704 }
705 else {
706 0 ▶ my $libs = $args{libs} || '';
Condition0%0/2
$args{'libs'} || ''
l!l
00
MC/DC0%0/1
$args{'libs'} || ''
$args{'libs'}
Truth table0%0/2
A
A= $args{'libs'}
Aresult
11
00
707 0 $base_out = "$base$Config{_exe}";
708 0 $cccmd = "$cc -o $base_out $ccflags $base.c $libs $errornull";
709 }
710  
711 0 ▶ printf "${indent}cccmd = $cccmd\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
712 0 my $res = system($cccmd);
713 0 ▶ $ok = defined($res) && $res == 0 && -s $base_out;
Condition0%0/6
defined $res && $res == 0 && -s $base_out
!ll&&!rl&&r
000
defined $res and $res == 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $res && $res == 0 && -s $base_out
defined $res $res == 0 -s $base_out
Truth table0%0/4
A and B && C
A= defined $resB= $res == 0C= -s $base_out
ABCresult
0XX0
10X0
1100
1111
714  
715 0 ▶ if ($ok && !$args{nolink} && !-x $base_out) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and not $args{"nolink"} and not -x $base_out) 0 0 0
Condition0%0/6
$ok and not $args{"nolink"} and not -x $base_out
!ll&&!rl&&r
000
$ok and not $args{"nolink"}
!ll&&!rl&&r
000
MC/DC0%0/3
$ok and not $args{"nolink"} and not -x $base_out
$ok not $args{"nolink"} not -x $base_out
Truth table0%0/4
A and not(B) and not(C)
A= $okB= not $args{"nolink"}C= not -x $base_out
ABCresult
0XX0
10X0
1100
1111
716 0 $ok = 0;
717 }
718  
719 0 ▶ if ( $ok && $args{run} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and $args{"run"}) 0 0 0
Condition0%0/3
$ok and $args{"run"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ok and $args{"run"}
$ok $args{"run"}
Truth table0%0/3
A and B
A= $okB= $args{"run"}
ABresult
0X0
100
111
720 # some Imager module probes use files shipped with the module
721 # so run from the original directory so they're visible
722 chdir $state->{start_dir}
723 0 ▶ or die "Cannot return to original current directory $state->{start_dir}: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $state->{"start_dir"} or die qq[Cannot return to original current directory $state->{"start_dir"}: $!\n] 0 0 0
724  
725 my $tmp_exe =
726 0 File::Spec->catfile($state->{tmpdir}, $base_out);
727 0 my @run = $tmp_exe;
728 0 ▶ unshift @run, $Config{run} if $Config{run} && -e $Config{run};
Branch: 1 branch
BranchTrueFalseTotal
if $Imager::Probe::Config{"run"} and -e $Imager::Probe::Config{"run"} 0 0 0
Condition0%0/3
$Imager::Probe::Config{"run"} and -e $Imager::Probe::Config{"run"}
!ll&&!rl&&r
000
MC/DC0%0/2
$Imager::Probe::Config{"run"} and -e $Imager::Probe::Config{"run"}
$Imager::Probe::Config{"run"} -e $Imager::Probe::Config{"run"}
Truth table0%0/3
A and B
A= $Imager::Probe::Config{"run"}B= -e $Imager::Probe::Config{"run"}
ABresult
0X0
100
111
729 0 ▶ printf "${indent}Running $tmp_exe..." if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
730 0 ▶ if (system(@run) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (system(@run) == 0) { } 0 0 0
731 0 $ok = 1;
732 0 ▶ print "${indent} success\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
733 } else {
734 0 $ok = 0;
735 0 my $errno = $? >> 8;
736 0 local $! = $errno;
737 0 ▶ printf <<EOF if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
738  
739 ${indent}*** The test run of '$tmp_exe' failed: status $?
740 ${indent}*** (the status means: errno = $errno or '$!')
741 EOF
742 }
743 }
744 # now cleaned up with the temp dir
745 # unlink("$tmp.c", $tmp_out);
746 }
747  
748 # redundant but harmless if we ran the test executable
749 chdir $state->{start_dir}
750 0 ▶ or die "Cannot return to original current directory $state->{start_dir}: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $state->{"start_dir"} or die qq[Cannot return to original current directory $state->{"start_dir"}: $!\n] 0 0 0
751  
752  
753 0 return $ok;
754 }
755  
756 1 1;
757  
758 __END__
« blib/lib/Imager/Font/Wrap.pm ↑ Summary blib/lib/Imager/Preprocess.pm »