line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Alien::Base::PkgConfig; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
443916
|
use strict; |
|
4
|
|
|
|
|
39
|
|
|
4
|
|
|
|
|
116
|
|
4
|
4
|
|
|
4
|
|
27
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
105
|
|
5
|
4
|
|
|
4
|
|
91
|
use 5.008004; |
|
4
|
|
|
|
|
11
|
|
6
|
4
|
|
|
4
|
|
26
|
use Carp; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
262
|
|
7
|
4
|
|
|
4
|
|
60
|
use Config; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
183
|
|
8
|
4
|
|
|
4
|
|
711
|
use Path::Tiny qw( path ); |
|
4
|
|
|
|
|
10046
|
|
|
4
|
|
|
|
|
213
|
|
9
|
4
|
|
|
4
|
|
475
|
use Capture::Tiny qw( capture_stderr ); |
|
4
|
|
|
|
|
20035
|
|
|
4
|
|
|
|
|
2958
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: Private legacy pkg-config class for Alien::Base |
12
|
|
|
|
|
|
|
our $VERSION = '2.47'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
1
|
|
|
1
|
0
|
5365
|
my $class = shift; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# allow creation of an object from a full spec. |
19
|
1
|
50
|
|
|
|
5
|
if (ref $_[0] eq 'HASH') { |
20
|
0
|
|
|
|
|
0
|
return bless $_[0], $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
3
|
my ($path) = @_; |
24
|
1
|
50
|
|
|
|
2
|
croak "Must specify a file" unless defined $path; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
9
|
$path = path( $path )->absolute; |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
149
|
my($name) = $path->basename =~ /^(.*)\.pc$/; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
27
|
my $self = { |
31
|
|
|
|
|
|
|
package => $name, |
32
|
|
|
|
|
|
|
vars => { pcfiledir => $path->parent->stringify }, |
33
|
|
|
|
|
|
|
keywords => {}, |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
52
|
bless $self, $class; |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
20
|
$self->read($path); |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
5
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub read { |
44
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
45
|
1
|
|
|
|
|
6
|
my ($path) = @_; |
46
|
|
|
|
|
|
|
|
47
|
1
|
50
|
|
|
|
9
|
open my $fh, '<', $path |
48
|
|
|
|
|
|
|
or croak "Cannot open .pc file $path: $!"; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
72
|
while (my $line = <$fh>) { |
51
|
9
|
100
|
|
|
|
37
|
if ($line =~ /^([^=:]+?)=([^\n\r]*)/) { |
|
|
100
|
|
|
|
|
|
52
|
2
|
|
|
|
|
14
|
$self->{vars}{$1} = $2; |
53
|
|
|
|
|
|
|
} elsif ($line =~ /^([^=:]+?):\s*([^\n\r]*)/) { |
54
|
6
|
|
|
|
|
36
|
$self->{keywords}{$1} = $2; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# getter/setter for vars |
60
|
|
|
|
|
|
|
sub var { |
61
|
2
|
|
|
2
|
0
|
2797
|
my $self = shift; |
62
|
2
|
|
|
|
|
5
|
my ($var, $newval) = @_; |
63
|
2
|
100
|
|
|
|
5
|
if (defined $newval) { |
64
|
1
|
|
|
|
|
2
|
$self->{vars}{$var} = $newval; |
65
|
|
|
|
|
|
|
} |
66
|
2
|
|
|
|
|
9
|
return $self->{vars}{$var}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# abstract keywords and other vars in terms of "pure" vars |
70
|
|
|
|
|
|
|
sub make_abstract { |
71
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
72
|
2
|
50
|
|
|
|
7
|
die "make_abstract needs a key (and possibly a value)" unless @_; |
73
|
2
|
|
|
|
|
4
|
my ($var, $value) = @_; |
74
|
|
|
|
|
|
|
|
75
|
2
|
50
|
|
|
|
6
|
$value = defined $value ? $value : $self->{vars}{$var}; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# convert other vars |
78
|
2
|
|
|
|
|
2
|
foreach my $key (keys %{ $self->{vars} }) { |
|
2
|
|
|
|
|
5
|
|
79
|
6
|
100
|
|
|
|
14
|
next if $key eq $var; # don't overwrite the current var |
80
|
4
|
|
|
|
|
34
|
$self->{vars}{$key} =~ s/\Q$value\E/\$\{$var\}/g; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# convert keywords |
84
|
2
|
|
|
|
|
31
|
foreach my $key (keys %{ $self->{keywords} }) { |
|
2
|
|
|
|
|
8
|
|
85
|
12
|
|
|
|
|
57
|
$self->{keywords}{$key} =~ s/\Q$value\E/\$\{$var\}/g; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _interpolate_vars { |
91
|
6
|
|
|
6
|
|
10
|
my $self = shift; |
92
|
6
|
|
|
|
|
10
|
my ($string, $override) = @_; |
93
|
|
|
|
|
|
|
|
94
|
6
|
|
100
|
|
|
34
|
$override ||= {}; |
95
|
|
|
|
|
|
|
|
96
|
6
|
|
|
|
|
24
|
foreach my $key (keys %$override) { |
97
|
|
|
|
|
|
|
carp "Overriden pkg-config variable $key, contains no data" |
98
|
1
|
50
|
|
|
|
3
|
unless $override->{$key}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
6
|
50
|
|
|
|
18
|
if (defined $string) { |
102
|
6
|
100
|
|
|
|
32
|
1 while $string =~ s/\$\{(.*?)\}/$override->{$1} || $self->{vars}{$1}/e; |
|
13
|
|
|
|
|
95
|
|
103
|
|
|
|
|
|
|
} |
104
|
6
|
|
|
|
|
39
|
return $string; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub keyword { |
108
|
6
|
|
|
6
|
0
|
10
|
my $self = shift; |
109
|
6
|
|
|
|
|
11
|
my ($keyword, $override) = @_; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
{ |
112
|
4
|
|
|
4
|
|
31
|
no warnings 'uninitialized'; |
|
4
|
|
|
|
|
27
|
|
|
4
|
|
|
|
|
1184
|
|
|
6
|
|
|
|
|
7
|
|
113
|
6
|
50
|
66
|
|
|
19
|
croak "overrides passed to 'keyword' must be a hashref" |
114
|
|
|
|
|
|
|
if defined $override and ref $override ne 'HASH'; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
6
|
|
|
|
|
24
|
return $self->_interpolate_vars( $self->{keywords}{$keyword}, $override ); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $pkg_config_command; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub pkg_config_command { |
123
|
2
|
100
|
|
2
|
0
|
8
|
unless (defined $pkg_config_command) { |
124
|
|
|
|
|
|
|
capture_stderr { |
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
|
50
|
33
|
1
|
|
3798
|
if (`pkg-config --version` && $? == 0 && !($^O eq 'solaris' && $Config{ptrsize} == 8)) { |
|
|
|
0
|
|
|
|
|
|
|
|
33
|
|
|
|
|
133
|
0
|
|
|
|
|
0
|
$pkg_config_command = 'pkg-config'; |
134
|
|
|
|
|
|
|
} else { |
135
|
1
|
|
|
|
|
895
|
require PkgConfig; |
136
|
1
|
|
|
|
|
116213
|
$pkg_config_command = "$^X $INC{'PkgConfig.pm'}"; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
1
|
|
|
|
|
26
|
} |
140
|
|
|
|
|
|
|
|
141
|
2
|
|
|
|
|
988
|
$pkg_config_command; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub TO_JSON |
145
|
|
|
|
|
|
|
{ |
146
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
147
|
0
|
|
|
|
|
|
my %hash = %$self; |
148
|
0
|
|
|
|
|
|
$hash{'__CLASS__'} = ref($self); |
149
|
0
|
|
|
|
|
|
\%hash; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
__END__ |