blib/lib/Alien/Base/PkgConfig.pm

filter: Statementstmt 92.9% 79 / 85 Branchbran 71.8% 23 / 32 Conditioncond 47.0% 8 / 17 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 94.1% 16 / 17 Podpod 0.0% 0 / 7 totaltotal 76.0% 127 / 167 CC 26 SCAR 15.6
CC
26
Cov
82%
__ANON__
10.4
_interpolate_vars
7.2
make_abstract
6.1
CRAP 4.8
« blib/lib/Alien/Build/CommandSequence.pm ↑ Summary blib/lib/Alien/Build/Log/Abbreviate.pm »
1 package Alien::Base::PkgConfig;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Capture::Tiny qw( capture_stderr );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # ABSTRACT: Private legacy pkg-config class for Alien::Base
12 4 our $VERSION = '2.88'; # VERSION
13  
14  
15 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod undocumented
16 1 my $class = shift;
17  
18 # allow creation of an object from a full spec.
19 1 ▶ if (ref $_[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "HASH") 0 1 1
20 0 return bless $_[0], $class;
21 }
22  
23 1 my ($path) = @_;
24 1 ▶ croak "Must specify a file" unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 1 1
25  
26 1 $path = path( $path )->absolute;
27  
28 1 my($name) = $path->basename =~ /^(.*)\.pc$/;
29  
30 1 my $self = {
31 package => $name,
32 vars => { pcfiledir => $path->parent->stringify },
33 keywords => {},
34 };
35  
36 1 bless $self, $class;
37  
38 1 $self->read($path);
39  
40 1 return $self;
41 }
42  
43 1 ▶sub read {
Subroutine read: called CC=5 SCAR=16.1
Pod undocumented
44 1 my $self = shift;
45 1 my ($path) = @_;
46  
47 1 ▶ open my $fh, '<', $path
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $path or croak("Cannot open .pc file ${path}: $!") 1 0 1
48 or croak "Cannot open .pc file $path: $!";
49  
50 1 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 9 1 10
51 9 ▶ if ($line =~ /^([^=:]+?)=([^\n\r]*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^([^=:]+?)=([^\n\r]*)/) { } 2 7 9
elsif ($line =~ /^([^=:]+?):\s*([^\n\r]*)/) { } 6 1 7
52 2 $self->{vars}{$1} = $2;
53 } elsif ($line =~ /^([^=:]+?):\s*([^\n\r]*)/) {
54 6 $self->{keywords}{$1} = $2;
55 }
56 }
57 }
58  
59 # getter/setter for vars
60 2 ▶sub var {
Subroutine var: called CC=2 SCAR=6.9
Pod undocumented
61 2 my $self = shift;
62 2 my ($var, $newval) = @_;
63 2 ▶ if (defined $newval) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newval) 1 1 2
64 1 $self->{vars}{$var} = $newval;
65 }
66 2 return $self->{vars}{$var};
67 }
68  
69 # abstract keywords and other vars in terms of "pure" vars
70 2 ▶sub make_abstract {
Subroutine make_abstract: called CC=6 SCAR=18.0
Pod undocumented
71 2 my $self = shift;
72 2 ▶ die "make_abstract needs a key (and possibly a value)" unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 2 2
73 2 my ($var, $value) = @_;
74  
75 2 ▶ $value = defined $value ? $value : $self->{vars}{$var};
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 2 2
76  
77 # convert other vars
78 2 foreach my $key (keys %{ $self->{vars} }) {
79 6 ▶ next if $key eq $var; # don't overwrite the current var
Branch: 1 branch
BranchTrueFalseTotal
if $key eq $var 2 4 6
80 4 $self->{vars}{$key} =~ s/\Q$value\E/\$\{$var\}/g;
81 }
82  
83 # convert keywords
84 2 foreach my $key (keys %{ $self->{keywords} }) {
85 12 $self->{keywords}{$key} =~ s/\Q$value\E/\$\{$var\}/g;
86 }
87  
88 }
89  
90 6 ▶sub _interpolate_vars {
Subroutine _interpolate_vars: called CC=7 SCAR=19.7
91 6 my $self = shift;
92 6 my ($string, $override) = @_;
93  
94 6 ▶ $override ||= {};
Condition100%2/2
$override ||= {}
l!l
15
MC/DC100%1/1
$override ||= {}
$override
Truth table100%2/2
A
A= $override
Aresult
11
00
95  
96 6 foreach my $key (keys %$override) {
97 carp "Overriden pkg-config variable $key, contains no data"
98 1 ▶ unless $override->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $override->{$key} 0 1 1
99 }
100  
101 6 ▶ if (defined $string) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) 6 0 6
102 6 ▶ 1 while $string =~ s/\$\{(.*?)\}/$override->{$1} || $self->{vars}{$1}/e;
Branch: 1 branch
BranchTrueFalseTotal
$string =~ s/\$\{(.*?)\}/$override->{$1} or $self->{"vars"}{$1};/e and do { '???' } 13 6 19
Condition66%2/3
$override->{$1} || $self->{'vars'}{$1}
l!l&&r!l&&!r
1120
MC/DC0%0/2
$override->{$1} || $self->{'vars'}{$1}
$override->{$1} $self->{'vars'}{$1}
Truth table66%2/3
A || B
A= $override->{$1}B= $self->{'vars'}{$1}
ABresult
1X1
011
000
103 }
104 6 return $string;
105 }
106  
107 6 ▶sub keyword {
Subroutine keyword: called CC=3 SCAR=11.1
Pod undocumented
108 6 my $self = shift;
109 6 my ($keyword, $override) = @_;
110  
111 {
112 4 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
113 6 ▶ croak "overrides passed to 'keyword' must be a hashref"
Branch: 1 branch
BranchTrueFalseTotal
if defined $override and ref $override ne "HASH" 0 6 6
Condition66%2/3
defined $override and ref $override ne "HASH"
!ll&&!rl&&r
510
MC/DC0%0/2
defined $override and ref $override ne "HASH"
defined $override ref $override ne "HASH"
Truth table66%2/3
A and B
A= defined $overrideB= ref $override ne "HASH"
ABresult
0X0
100
111
114 if defined $override and ref $override ne 'HASH';
115 }
116  
117 6 return $self->_interpolate_vars( $self->{keywords}{$keyword}, $override );
118 }
119  
120 4 my $pkg_config_command;
121  
122 2 ▶sub pkg_config_command {
Subroutine pkg_config_command: called CC=2 SCAR=8.6
Pod undocumented
123 2 ▶ unless (defined $pkg_config_command) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pkg_config_command) 1 1 2
124 1 ▶ capture_stderr {
Subroutine __ANON__: called CC=5 SCAR=23.4
125  
126 # For now we prefer PkgConfig.pm over pkg-config on
127 # Solaris 64 bit Perls. We may need to do this on
128 # other platforms, in which case this logic should
129 # be abstracted so that it can be shared here and
130 # in Build.PL
131  
132 1 ▶ if (`pkg-config --version` && $? == 0 && !($^O eq 'solaris' && $Config{ptrsize} == 8)) {
Branch: 1 branch
BranchTrueFalseTotal
if (`pkg-config --version` and $? == 0 and not $^O eq 'solaris' && $Alien::Base::PkgConfig::Config{'ptrsize'} == 8) { } 0 1 1
Condition22%2/9
`pkg-config --version` and $? == 0 and not $^O eq "solaris" && $Alien::Base::PkgConfig::Config{"ptrsize"} == 8
!ll&&!rl&&r
100
`pkg-config --version` and $? == 0
!ll&&!rl&&r
100
$^O eq 'solaris' && $Alien::Base::PkgConfig::Config{'ptrsize'} == 8
!ll&&!rl&&r
000
MC/DC0%0/4
`pkg-config --version` and $? == 0 and not $^O eq "solaris" && $Alien::Base::PkgConfig::Config{"ptrsize"} == 8
`pkg-config --version` $? == 0 $^O eq 'solaris' $Alien::Base::PkgConfig::Config{'ptrsize'} == 8
Truth table20%1/5
A and B and not(C && D)
A= `pkg-config --version`B= $? == 0C= $^O eq 'solaris'D= $Alien::Base::PkgConfig::Config{'ptrsize'} == 8
ABCDresult
0XXX0
10XX0
11110
110X1
11101
133 0 $pkg_config_command = 'pkg-config';
134 } else {
135 1 require PkgConfig;
136 1 $pkg_config_command = "$^X $INC{'PkgConfig.pm'}";
137 }
138 }
139 1 }
140  
141 2 $pkg_config_command;
142 }
143  
144 sub TO_JSON
145 0 ▶{
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
146 0 my($self) = @_;
147 0 my %hash = %$self;
148 0 $hash{'__CLASS__'} = ref($self);
149 0 \%hash;
150 }
151  
152 4 1;
153  
154 __END__
« blib/lib/Alien/Build/CommandSequence.pm ↑ Summary blib/lib/Alien/Build/Log/Abbreviate.pm »