blib/lib/FFI/CheckLib.pm

filter: Statementstmt 84.0% 195 / 232 Branchbran 71.0% 91 / 128 Conditioncond 57.7% 26 / 45 MC/DCmcdc 30.7% 8 / 26 Subroutinesub 78.5% 22 / 28 Podpod 100% 9 / 9 totaltotal 75.0% 351 / 468 CC 79 SCAR 34.5
CC
79
Cov
77%
find_lib
62.4
find_lib_or_exit
30.0
find_lib_or_die
30.0
CRAP 31.7
↑ Summary corpus/lib/Alien/libbar.pm »
1 package FFI::CheckLib;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use List::Util 1.33 qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Carp qw( croak carp );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Env qw( @FFI_CHECKLIB_PATH );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 our @EXPORT = qw(
12 find_lib
13 assert_lib
14 check_lib
15 check_lib_or_exit
16 find_lib_or_exit
17 find_lib_or_die
18 );
19  
20 6 our @EXPORT_OK = qw(
21 which
22 where
23 has_symbols
24 );
25  
26 # ABSTRACT: Check that a library is available for FFI
27 6 our $VERSION = '0.31'; # VERSION
28  
29  
30 6 our $system_path = [];
31 6 ▶our $os ||= $^O;
Condition33%1/3
our $os ||= $^O
l!l&&r!l&&!r
600
MC/DC0%0/2
our $os ||= $^O
our $os $^O
Truth table33%1/3
A ||= B
A= our $osB= $^O
ABresult
1X1
011
000
32 6 my $try_ld_on_text = 0;
33  
34 1 ▶sub _homebrew_lib_path {
Subroutine _homebrew_lib_path: called CC=2 SCAR=9.2
35 1 require File::Which;
36 1 ▶ return undef unless File::Which::which('brew');
Branch: 1 branch
BranchTrueFalseTotal
unless File::Which::which("brew") 1 0 1
37 0 chomp(my $brew_path = (qx`brew --prefix`)[0]);
38 0 return "$brew_path/lib";
39 }
40  
41 1 ▶sub _macports_lib_path {
Subroutine _macports_lib_path: called CC=2 SCAR=8.4
42 1 require File::Which;
43 1 my $port_path = File::Which::which('port');
44 1 ▶ return undef unless $port_path;
Branch: 1 branch
BranchTrueFalseTotal
unless $port_path 1 0 1
45 0 $port_path =~ s|bin/port|lib|;
46 0 return $port_path;
47 }
48  
49 6 ▶sub _darwin_extra_paths {
Subroutine _darwin_extra_paths: called CC=5 SCAR=16.1
50 6 ▶ my $pkg_managers = lc( $ENV{FFI_CHECKLIB_PACKAGE} || 'homebrew,macports' );
Condition100%2/2
$ENV{'FFI_CHECKLIB_PACKAGE'} || 'homebrew,macports'
l!l
42
MC/DC100%1/1
$ENV{'FFI_CHECKLIB_PACKAGE'} || 'homebrew,macports'
$ENV{'FFI_CHECKLIB_PACKAGE'}
Truth table100%2/2
A
A= $ENV{'FFI_CHECKLIB_PACKAGE'}
Aresult
11
00
51 6 ▶ return () if $pkg_managers eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
if $pkg_managers eq "none" 1 5 6
52 5 my $supported_managers = {
53 homebrew => \&_homebrew_lib_path,
54 macports => \&_macports_lib_path
55 };
56 5 my @extra_paths = ();
57 5 foreach my $pkg_manager (split( /,/, $pkg_managers )) {
58 8 ▶ if (my $lib_path = $supported_managers->{$pkg_manager}()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lib_path = $supported_managers->{$pkg_manager}->()) 6 2 8
59 6 push @extra_paths, $lib_path;
60 }
61 }
62 5 return @extra_paths;
63 }
64  
65 6 my @extra_paths = ();
66 6 ▶if($os eq 'MSWin32' || $os eq 'msys')
Branch: 1 branch
BranchTrueFalseTotal
if ($FFI::CheckLib::os eq 'MSWin32' or $FFI::CheckLib::os eq 'msys') { } 2 4 6
Condition100%3/3
$FFI::CheckLib::os eq "MSWin32" or $FFI::CheckLib::os eq "msys"
l!l&&r!l&&!r
114
MC/DC100%2/2
$FFI::CheckLib::os eq "MSWin32" or $FFI::CheckLib::os eq "msys"
$FFI::CheckLib::os eq "MSWin32" $FFI::CheckLib::os eq "msys"
Truth table100%3/3
A or B
A= $FFI::CheckLib::os eq "MSWin32"B= $FFI::CheckLib::os eq "msys"
ABresult
1X1
011
000
67 {
68 2 $system_path = eval {
69 2 require Env;
70 2 Env->import('@PATH');
71 2 \our @PATH;
72 };
73 2 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
74 }
75 else
76 {
77 4 $system_path = eval {
78 4 require DynaLoader;
79 6 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
80 4 \@DynaLoader::dl_library_path;
81 };
82 4 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 4 4
83 4 ▶ @extra_paths = _darwin_extra_paths() if $os eq 'darwin';
Branch: 1 branch
BranchTrueFalseTotal
if $FFI::CheckLib::os eq "darwin" 1 3 4
84 }
85  
86 6 our $pattern = [ qr{^lib(.*?)\.so(?:\.([0-9]+(?:\.[0-9]+)*))?$} ];
87 6 our $version_split = qr/\./;
88  
89 6 ▶if($os eq 'cygwin')
Branch: 5 branches
BranchTrueFalseTotal
if ($FFI::CheckLib::os eq 'cygwin') { } 1 5 6
elsif ($FFI::CheckLib::os eq 'msys') { } 1 4 5
elsif ($FFI::CheckLib::os eq 'MSWin32') { } 1 3 4
elsif ($FFI::CheckLib::os eq 'darwin') { } 1 2 3
elsif ($FFI::CheckLib::os eq 'linux') { } 2 0 2
90 {
91 1 push @$pattern, qr{^cyg(.*?)(?:-([0-9])+)?\.dll$};
92 }
93 elsif($os eq 'msys')
94 {
95 # doesn't seem as though msys uses psudo libfoo.so files
96 # in the way that cygwin sometimes does. we can revisit
97 # this if we find otherwise.
98 1 $pattern = [ qr{^msys-(.*?)(?:-([0-9])+)?\.dll$} ];
99 }
100 elsif($os eq 'MSWin32')
101 {
102 # handle cases like libgeos-3-7-0___.dll, libproj_9_1.dll and libgtk-2.0-0.dll
103 1 $pattern = [ qr{^(?:lib)?(\w+?)(?:[_-]([0-9\-\._]+))?_*\.dll$}i ];
104 1 $version_split = qr/[_\-]/;
105 }
106 elsif($os eq 'darwin')
107 {
108 1 push @$pattern, qr{^lib(.*?)(?:\.([0-9]+(?:\.[0-9]+)*))?\.(?:dylib|bundle)$};
109 }
110 elsif($os eq 'linux')
111 {
112 2 ▶ if(-e '/etc/redhat-release' && -x '/usr/bin/ld')
Branch: 1 branch
BranchTrueFalseTotal
if (-e "/etc/redhat-release" and -x "/usr/bin/ld") 0 2 2
Condition33%1/3
-e "/etc/redhat-release" and -x "/usr/bin/ld"
!ll&&!rl&&r
200
MC/DC0%0/2
-e "/etc/redhat-release" and -x "/usr/bin/ld"
-e "/etc/redhat-release" -x "/usr/bin/ld"
Truth table33%1/3
A and B
A= -e "/etc/redhat-release"B= -x "/usr/bin/ld"
ABresult
0X0
100
111
113 {
114 0 $try_ld_on_text = 1;
115 }
116 }
117  
118 sub _matches
119 1577 ▶{
Subroutine _matches: called CC=4 SCAR=13.9
120 1577 my($filename, $path) = @_;
121  
122 1577 foreach my $regex (@$pattern)
123 {
124 return [
125 2093 ▶ $1, # 0 capture group 1 library name
Branch: 2 branches
BranchTrueFalseTotal
if $filename =~ /$regex/ 1030 1063 2093
defined $2 ? : 754 276 1030
126 File::Spec->catfile($path, $filename), # 1 full path to library
127 defined $2 ? (split $version_split, $2) : (), # 2... capture group 2 library version
128 ] if $filename =~ $regex;
129 }
130 547 return ();
131 }
132  
133 sub _cmp
134 204 ▶{
Subroutine _cmp: called CC=7 SCAR=19.5
135 204 my($A,$B) = @_;
136  
137 204 ▶ return $A->[0] cmp $B->[0] if $A->[0] ne $B->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $A->[0] ne $B->[0] 52 152 204
138  
139 152 my $i=2;
140 152 while(1)
141 {
142 256 ▶ return 0 if !defined($A->[$i]) && !defined($B->[$i]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $A->[$i] or defined $B->[$i] 0 256 256
Condition66%2/3
defined $A->[$i] or defined $B->[$i]
l!l&&r!l&&!r
1561000
MC/DC0%0/2
defined $A->[$i] or defined $B->[$i]
defined $A->[$i] defined $B->[$i]
Truth table66%2/3
A or B
A= defined $A->[$i]B= defined $B->[$i]
ABresult
1X1
011
000
143 256 ▶ return -1 if !defined $A->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $A->[$i] 100 156 256
144 156 ▶ return 1 if !defined $B->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $B->[$i] 38 118 156
145 118 ▶ return $B->[$i] <=> $A->[$i] if $A->[$i] != $B->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $A->[$i] != $B->[$i] 14 104 118
146 104 $i++;
147 }
148 }
149  
150  
151 6 my $diagnostic;
152  
153 sub _is_binary
154 0 ▶{
Subroutine _is_binary: not called CC=1 SCAR=6.9
155 0 -B $_[0]
156 }
157  
158 sub find_lib
159 82 ▶{
Subroutine find_lib: called CC=46 SCAR=41.3
160 82 my(%args) = @_;
161  
162 82 undef $diagnostic;
163 82 ▶ croak "find_lib requires lib argument" unless defined $args{lib};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"lib"} 0 82 82
164  
165 82 ▶ my $recursive = $args{_r} || $args{recursive} || 0;
Condition80%4/5
$args{'_r'} || $args{'recursive'} || 0
l!l
280
$args{"_r"} or $args{"recursive"}
l!l&&r!l&&!r
0280
MC/DC50%1/2
$args{'_r'} || $args{'recursive'} || 0
$args{"_r"} $args{"recursive"}
Truth table66%2/3
A or B
A= $args{"_r"}B= $args{"recursive"}
ABresult
1X1
011
000
166  
167 # make arguments be lists.
168 82 foreach my $arg (qw( lib libpath symbol verify alien ))
169 {
170 410 ▶ next if ref $args{$arg} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args{$arg} eq "ARRAY" 20 390 410
171 390 ▶ if(defined $args{$arg})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{$arg}) { } 97 293 390
172 {
173 97 $args{$arg} = [ $args{$arg} ];
174 }
175 else
176 {
177 293 $args{$arg} = [];
178 }
179 }
180  
181 82 ▶ if(defined $args{systempath} && !ref($args{systempath}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"systempath"} and not ref $args{"systempath"}) 0 82 82
Condition33%1/3
defined $args{"systempath"} and not ref $args{"systempath"}
!ll&&!rl&&r
8200
MC/DC0%0/2
defined $args{"systempath"} and not ref $args{"systempath"}
defined $args{"systempath"} not ref $args{"systempath"}
Truth table33%1/3
A and not(B)
A= defined $args{"systempath"}B= not ref $args{"systempath"}
ABresult
0X0
100
111
182 {
183 0 $args{systempath} = [ $args{systempath} ];
184 }
185  
186 82 my @path = @{ $args{libpath} };
187 82 ▶ @path = map { _recurse($_) } @path if $recursive;
Branch: 1 branch
BranchTrueFalseTotal
if $recursive 2 80 82
188  
189 82 ▶ if(defined $args{systempath})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'systempath'}) { } 0 82 82
190 {
191 0 push @path, grep { defined } @{ $args{systempath} }
192 }
193 else
194 {
195 # This is a little convaluted, but:
196 # 1. These are modifications of what we consider the "system" path
197 # if systempath isn't explicitly passed in as systempath
198 # 2. FFI_CHECKLIB_PATH is considered an authortative modification
199 # so it goes first and overrides FFI_CHECKLIB_PACKAGE
200 # 3. otherwise FFI_CHECKLIB_PACKAGE does its thing and goes on
201 # the end because homebrew does a good job of not replacing
202 # anything in the system by default.
203 # 4. We finally add what we consider the "system" path to the end of
204 # the search path so that libpath will be searched first.
205 82 my @system_path = @$system_path;
206 82 ▶ if($ENV{FFI_CHECKLIB_PATH})
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'FFI_CHECKLIB_PATH'}) { } 2 80 82
207 {
208 2 @system_path = (@FFI_CHECKLIB_PATH, @system_path);
209 }
210 else
211 {
212 80 foreach my $extra_path (@extra_paths)
213 {
214 0 ▶ push @path, $extra_path unless any { $_ eq $extra_path } @path;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $_ eq $extra_path; } , @path) 0 0 0
215 }
216 }
217 82 push @path, @system_path;
218 }
219  
220 82 ▶ my $any = any { $_ eq '*' } @{ $args{lib} };
Subroutine __ANON__: called CC=1 SCAR=0.0
221 82 my %missing = map { $_ => 1 } @{ $args{lib} };
222 82 my %symbols = map { $_ => 1 } @{ $args{symbol} };
223 82 my @found;
224  
225 82 delete $missing{'*'};
226  
227 82 alien: foreach my $alien (reverse @{ $args{alien} })
228 {
229 5 ▶ unless($alien =~ /^([A-Za-z_][A-Za-z_0-9]*)(::[A-Za-z_][A-Za-z_0-9]*)*$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($alien =~ /^([A-Za-z_][A-Za-z_0-9]*)(::[A-Za-z_][A-Za-z_0-9]*)*$/) 1 4 5
230 {
231 1 croak "Doesn't appear to be a valid Alien name $alien";
232 }
233 4 ▶ unless(eval { $alien->can('dynamic_libs') })
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $alien->can("dynamic_libs") } }) 3 1 4
234 {
235 {
236 3 my $pm = "$alien.pm";
237 3 $pm =~ s/::/\//g;
238 3 local $@ = '';
239 3 eval { require $pm };
240 3 ▶ next alien if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 2 3
241 }
242 2 ▶ unless(eval { $alien->can('dynamic_libs') })
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $alien->can("dynamic_libs") } }) 1 1 2
243 {
244 1 croak "Alien $alien doesn't provide a dynamic_libs method";
245 }
246 }
247 2 unshift @path, [$alien->dynamic_libs];
248 }
249  
250 80 foreach my $path (@path)
251 {
252 169 ▶ next if ref $path ne 'ARRAY' && ! -d $path;
Branch: 1 branch
BranchTrueFalseTotal
if ref $path ne "ARRAY" and not -d $path 0 169 169
Condition66%2/3
ref $path ne "ARRAY" and not -d $path
!ll&&!rl&&r
21670
MC/DC0%0/2
ref $path ne "ARRAY" and not -d $path
ref $path ne "ARRAY" not -d $path
Truth table66%2/3
A and not(B)
A= ref $path ne "ARRAY"B= not -d $path
ABresult
0X0
100
111
253  
254 my @maybe =
255 # make determinist based on names and versions
256 141 sort { _cmp($a,$b) }
257 # Filter out the items that do not match the name that we are looking for
258 # Filter out any broken symbolic links
259 962 ▶ grep { ($any || $missing{$_->[0]} ) && (-e $_->[1]) }
Branch: 1 branch
BranchTrueFalseTotal
ref $path eq 'ARRAY' ? : 2 167 169
Condition83%5/6
($any || $missing{$_->[0]}) && -e $_->[1]
!ll&&!rl&&r
7820180
$any or $missing{$_->[0]}
l!l&&r!l&&!r
3177782
MC/DC66%2/3
($any || $missing{$_->[0]}) && -e $_->[1]
$any $missing{$_->[0]} -e $_->[1]
Truth table60%3/5
A or B && C
A= $anyB= $missing{$_->[0]}C= -e $_->[1]
ABCresult
00X0
1X00
0100
1X11
0111
260 ref $path eq 'ARRAY'
261 ? do {
262 map {
263 2 my($v, $d, $f) = File::Spec->splitpath($_);
264 2 _matches($f, File::Spec->catpath($v,$d,''));
265 } @$path;
266 }
267 169 : do {
268 167 my $dh;
269 167 opendir $dh, $path;
270 # get [ name, full_path ] mapping,
271 # each entry is a 2 element list ref
272 167 map { _matches($_,$path) } readdir $dh;
273 };
274  
275 169 ▶ if($try_ld_on_text && $args{try_linker_script})
Branch: 1 branch
BranchTrueFalseTotal
if ($try_ld_on_text and $args{"try_linker_script"}) 0 169 169
Condition33%1/3
$try_ld_on_text and $args{"try_linker_script"}
!ll&&!rl&&r
16900
MC/DC0%0/2
$try_ld_on_text and $args{"try_linker_script"}
$try_ld_on_text $args{"try_linker_script"}
Truth table33%1/3
A and B
A= $try_ld_on_textB= $args{"try_linker_script"}
ABresult
0X0
100
111
276 {
277 # This is tested in t/ci.t only
278 @maybe = map {
279 0 ▶ -B $_->[1] ? $_ : do {
Branch: 1 branch
BranchTrueFalseTotal
-B $_->[1] ? : 0 0 0
280 0 my($name, $so) = @$_;
281 0 my $output = `/usr/bin/ld -t $so -o /dev/null -shared`;
282 0 ▶ $output =~ /\((.*?lib.*\.so.*?)\)/
Branch: 1 branch
BranchTrueFalseTotal
$output =~ /\((.*?lib.*\.so.*?)\)/ ? : 0 0 0
283 ? [$name, $1]
284 : die "unable to parse ld output";
285 }
286 } @maybe;
287 }
288  
289 midloop:
290 169 foreach my $lib (@maybe)
291 {
292 180 ▶ next unless $any || $missing{$lib->[0]};
Branch: 1 branch
BranchTrueFalseTotal
unless $any or $missing{$lib->[0]} 67 113 180
Condition100%3/3
$any or $missing{$lib->[0]}
l!l&&r!l&&!r
311067
MC/DC100%2/2
$any or $missing{$lib->[0]}
$any $missing{$lib->[0]}
Truth table100%3/3
A or B
A= $anyB= $missing{$lib->[0]}
ABresult
1X1
011
000
293  
294 113 foreach my $verify (@{ $args{verify} })
295 {
296 48 ▶ next midloop unless $verify->(@$lib);
Branch: 1 branch
BranchTrueFalseTotal
unless &$verify(@$lib) 45 3 48
297 }
298  
299 68 delete $missing{$lib->[0]};
300  
301 68 ▶ if(%symbols)
Branch: 1 branch
BranchTrueFalseTotal
if (%symbols) 12 56 68
302 {
303 12 require DynaLoader;
304 12 my $dll = DynaLoader::dl_load_file($lib->[1],0);
305 12 foreach my $symbol (keys %symbols)
306 {
307 27 ▶ if(DynaLoader::dl_find_symbol($dll, $symbol) ? 1 : 0)
Branch: 2 branches
BranchTrueFalseTotal
if (DynaLoader::dl_find_symbol($dll, $symbol) ? 1 : 0) 21 6 27
DynaLoader::dl_find_symbol($dll, $symbol) ? : 21 6 27
308 {
309 21 delete $symbols{$symbol}
310 }
311 }
312 12 DynaLoader::dl_unload_file($dll);
313 }
314  
315 68 my $found = $lib->[1];
316  
317 68 ▶ unless($any)
Branch: 1 branch
BranchTrueFalseTotal
unless ($any) 65 3 68
318 {
319 65 ▶ while(-l $found)
Branch: 1 branch
BranchTrueFalseTotal
if (-l $found) 0 65 65
320 {
321 0 require File::Basename;
322 0 my $dir = File::Basename::dirname($found);
323 0 $found = File::Spec->rel2abs( readlink($found), $dir );
324 }
325 }
326  
327 68 push @found, $found;
328 }
329 }
330  
331 80 ▶ if(%missing)
Branch: 2 branches
BranchTrueFalseTotal
if (%missing) { } 17 63 80
elsif (%symbols) { } 6 57 63
332 {
333 17 my @missing = sort keys %missing;
334 17 ▶ if(@missing > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@missing > 1) { } 0 17 17
335 0 { $diagnostic = "libraries not found: @missing" }
336 else
337 17 { $diagnostic = "library not found: @missing" }
338 }
339 elsif(%symbols)
340 {
341 6 my @missing = sort keys %symbols;
342 6 ▶ if(@missing > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@missing > 1) { } 0 6 6
343 0 { $diagnostic = "symbols not found: @missing" }
344 else
345 6 { $diagnostic = "symbol not found: @missing" }
346 }
347  
348 80 ▶ return if %symbols;
Branch: 1 branch
BranchTrueFalseTotal
if %symbols 6 74 80
349 74 ▶ return $found[0] unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 27 47 74
350 47 return @found;
351 }
352  
353 sub _recurse
354 6 ▶{
Subroutine _recurse: called CC=2 SCAR=6.9
355 6 my($dir) = @_;
356 6 ▶ return unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 6 6
357 6 my $dh;
358 6 opendir $dh, $dir;
359 6 my @list = grep { -d $_ } map { File::Spec->catdir($dir, $_) } grep !/^\.\.?$/, readdir $dh;
360 6 closedir $dh;
361 6 ($dir, map { _recurse($_) } @list);
362 }
363  
364  
365 sub assert_lib
366 6 ▶{
Subroutine assert_lib: called CC=3 SCAR=11.2
Pod documented
367 6 ▶ croak $diagnostic || 'library not found' unless check_lib(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless check_lib(@_) 3 3 6
Condition50%1/2
$diagnostic || 'library not found'
l!l
30
MC/DC0%0/1
$diagnostic || 'library not found'
$diagnostic
Truth table50%1/2
A
A= $diagnostic
Aresult
11
00
368 }
369  
370  
371 sub check_lib_or_exit
372 0 ▶{
Subroutine check_lib_or_exit: not called CC=3 SCAR=24.8
Pod documented
373 0 ▶ unless(check_lib(@_))
Branch: 1 branch
BranchTrueFalseTotal
unless (check_lib(@_)) 0 0 0
374 {
375 0 ▶ carp $diagnostic || 'library not found';
Condition0%0/2
$diagnostic || 'library not found'
l!l
00
MC/DC0%0/1
$diagnostic || 'library not found'
$diagnostic
Truth table0%0/2
A
A= $diagnostic
Aresult
11
00
376 0 exit;
377 }
378 }
379  
380  
381 sub find_lib_or_exit
382 0 ▶{
Subroutine find_lib_or_exit: not called CC=5 SCAR=34.0
Pod documented
383 0 my(@libs) = find_lib(@_);
384 0 ▶ unless(@libs)
Branch: 1 branch
BranchTrueFalseTotal
unless (@libs) 0 0 0
385 {
386 0 ▶ carp $diagnostic || 'library not found';
Condition0%0/2
$diagnostic || 'library not found'
l!l
00
MC/DC0%0/1
$diagnostic || 'library not found'
$diagnostic
Truth table0%0/2
A
A= $diagnostic
Aresult
11
00
387 0 exit;
388 }
389 0 ▶ return unless @libs;
Branch: 1 branch
BranchTrueFalseTotal
unless @libs 0 0 0
390 0 ▶ wantarray ? @libs : $libs[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
391 }
392  
393  
394 sub find_lib_or_die
395 0 ▶{
Subroutine find_lib_or_die: not called CC=5 SCAR=34.0
Pod documented
396 0 my(@libs) = find_lib(@_);
397 0 ▶ unless(@libs)
Branch: 1 branch
BranchTrueFalseTotal
unless (@libs) 0 0 0
398 {
399 0 ▶ croak $diagnostic || 'library not found';
Condition0%0/2
$diagnostic || 'library not found'
l!l
00
MC/DC0%0/1
$diagnostic || 'library not found'
$diagnostic
Truth table0%0/2
A
A= $diagnostic
Aresult
11
00
400 }
401 0 ▶ return unless @libs;
Branch: 1 branch
BranchTrueFalseTotal
unless @libs 0 0 0
402 0 ▶ wantarray ? @libs : $libs[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
403 }
404  
405  
406 sub check_lib
407 12 ▶{
Subroutine check_lib: called CC=2 SCAR=6.9
Pod documented
408 12 ▶ find_lib(@_) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
find_lib(@_) ? : 6 6 12
409 }
410  
411  
412 sub which
413 1 ▶{
Subroutine which: called CC=2 SCAR=7.1
Pod documented
414 1 my($name) = @_;
415 1 ▶ croak("cannot which *") if $name eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "*" 0 1 1
416 1 scalar find_lib( lib => $name );
417 }
418  
419  
420 sub where
421 2 ▶{
Subroutine where: called CC=2 SCAR=7.1
Pod documented
422 2 my($name) = @_;
423 $name eq '*'
424 ? find_lib(lib => '*')
425 0 ▶ : find_lib(lib => '*', verify => sub { $_[0] eq $name });
Subroutine __ANON__: not called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
$name eq '*' ? : 1 1 2
426 }
427  
428  
429 sub has_symbols
430 6 ▶{
Subroutine has_symbols: called CC=3 SCAR=11.0
Pod documented
431 6 my($path, @symbols) = @_;
432 6 require DynaLoader;
433 6 my $dll = DynaLoader::dl_load_file($path, 0);
434  
435 6 my $ok = 1;
436  
437 6 foreach my $symbol (@symbols)
438 {
439 11 ▶ unless(DynaLoader::dl_find_symbol($dll, $symbol))
Branch: 1 branch
BranchTrueFalseTotal
unless (DynaLoader::dl_find_symbol($dll, $symbol)) 2 9 11
440 {
441 2 $ok = 0;
442 2 last;
443 }
444 }
445  
446 6 DynaLoader::dl_unload_file($dll);
447  
448 6 $ok;
449 }
450  
451  
452 sub system_path
453 1 ▶{
Subroutine system_path: called CC=1 SCAR=0.0
Pod documented
454 1 $system_path;
455 }
456  
457 6 1;
458  
459 __END__
↑ Summary corpus/lib/Alien/libbar.pm »