| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | or croak "Cannot open .pc file $path: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | while (my $line = <$fh>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 9 | ▶ | if ($line =~ /^([^=:]+?)=([^\n\r]*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | my ($var, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | $value = defined $value ? $value : $self->{vars}{$var}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 ||= {}
MC/DC100%1/1
$override ||= {}
$override
Truth table100%2/2
A
A= $override
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | ▶ | if (defined $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | ▶ | 1 while $string =~ s/\$\{(.*?)\}/$override->{$1} || $self->{vars}{$1}/e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$override->{$1} || $self->{'vars'}{$1}
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $override and ref $override ne "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition22%2/9
`pkg-config --version` and $? == 0 and not $^O eq "solaris" && $Alien::Base::PkgConfig::Config{"ptrsize"} == 8
`pkg-config --version` and $? == 0
$^O eq 'solaris' && $Alien::Base::PkgConfig::Config{'ptrsize'} == 8
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||