blib/lib/Alien/Build/Plugin/PkgConfig/PPWrapper.pm

filter: Statementstmt 40.0% 22 / 55 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 77.7% 7 / 9 Podpod 100% 1 / 1 totaltotal 32.9% 30 / 91 CC 11 SCAR 43.4
CC
11
Cov
29%
__ANON__
132.0
init
2.0
BEGIN
1.0
CRAP 76.9
↑ Summary
1 package Alien::Build::Plugin::PkgConfig::PPWrapper;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Alien::Build;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Alien::Build::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Path::Tiny qw /path/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Which ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.03'; # VERSION
12  
13  
14 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
15 0 my($self, $meta) = @_;
16  
17 0 ▶ $meta->around_hook ( build => sub {
Subroutine __ANON__: not called CC=11 SCAR=48.8
18 0 my ($orig, $build, @args) = @_;
19
20 0 ▶ return if $build->install_type ne 'share';
Branch: 1 branch
BranchTrueFalseTotal
if $build->install_type ne "share" 0 0 0
21 0 ▶ return if $build->meta_prop->{out_of_source};
Branch: 1 branch
BranchTrueFalseTotal
if $build->meta_prop->{"out_of_source"} 0 0 0
22  
23 # wrapper is only needed on windows
24 0 ▶ return $orig->($build, @args)
Branch: 1 branch
BranchTrueFalseTotal
unless $^O =~ /mswin/i 0 0 0
25 if not $^O =~ /mswin/i;
26  
27 my $pk = File::Which::which ($ENV{PKG_CONFIG})
28 0 ▶ || File::Which::which ('ppkg-config')
Condition0%0/6
File::Which::which($ENV{'PKG_CONFIG'}) || File::Which::which('ppkg-config') || File::Which::which('pkg-config')
l!l&&r!l&&!r
000
File::Which::which($ENV{"PKG_CONFIG"}) or File::Which::which("ppkg-config")
l!l&&r!l&&!r
000
MC/DC0%0/3
File::Which::which($ENV{'PKG_CONFIG'}) || File::Which::which('ppkg-config') || File::Which::which('pkg-config')
File::Which::which($ENV{"PKG_CONFIG"}) File::Which::which("ppkg-config") File::Which::which('pkg-config')
Truth table0%0/4
A or B || C
A= File::Which::which($ENV{"PKG_CONFIG"})B= File::Which::which("ppkg-config")C= File::Which::which('pkg-config')
ABCresult
1XX1
01X1
0011
0000
29 || File::Which::which ('pkg-config');
30  
31 0 ▶ if (!defined $pk) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pk) 0 0 0
32 0 $build->log ("Could not locate ppkg-config or pkg-config in your path\n");
33 0 return $orig->($build, @args);
34 }
35  
36 0 $pk =~ s/\.bat$//i;
37 0 ▶ if (!(-e $pk && -e "$pk.bat")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $pk and -e "$pk.bat") 0 0 0
Condition0%0/3
-e $pk and -e "$pk.bat"
!ll&&!rl&&r
000
MC/DC0%0/2
-e $pk and -e "$pk.bat"
-e $pk -e "$pk.bat"
Truth table0%0/3
A and B
A= -e $pkB= -e "$pk.bat"
ABresult
0X0
100
111
38 0 $build->log ("$pk unlikely to be pure perl");
39 0 return $orig->($build, @args);
40 }
41  
42 0 my $perl = $^X;
43 0 $perl =~ s/\.exe$//i;
44 0 foreach my $path ($perl, $pk) {
45 0 $path =~ s{\\}{/}g;
46 0 $path =~ s{^([a-z]):/}{/$1/}i;
47 0 $path =~ s{\s}{\\ }g;
48 }
49  
50 0 my $wrapper = <<'EOWRAPPER'
51 #!perl
52 system ('##perl##', '##pk##', @ARGV);
53 exit $?;
54 EOWRAPPER
55 ;
56  
57 0 $wrapper =~ s/##perl##/$perl/gsm;
58 0 $wrapper =~ s/##pk##/$pk/;
59  
60 0 $build->log ("Pure perl pkg-config detected on windows.\n");
61 0 $build->log ("Wrapping $pk in shell script to cope with MSYS perl and paths.\n");
62 0 my $fname = Path::Tiny->new(File::Temp::tempdir( CLEANUP => 1 ))->child('pkg-config');
63 0 ▶ open my $fh, '>', $fname
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $fname or die "Unable to open pkg-config wrapper $fname, $!" 0 0 0
64 or die "Unable to open pkg-config wrapper $fname, $!";
65 0 print {$fh} $wrapper;
66 0 close ($fh);
67 0 $build->log ("Setting \$ENV{PKG_CONFIG} to point to $fname\n");
68
69 0 local $ENV{PKG_CONFIG} = $fname;
70
71 0 return $orig->($build, @args);
72 0 });
73  
74 }
75  
76 1 1;
77  
78 __END__
↑ Summary