Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 129 lines (96 sloc) 2.623 kb
7eea0d4 @jberger Added A::B::PkgConfig and (some) tests for handling pc files
jberger authored
1 package Alien::Base::PkgConfig;
2
3 use strict;
4 use warnings;
5
3200649 @jberger bump version and update Changes
jberger authored
6 our $VERSION = '0.000_008';
f4322ac @jberger Added VERSION to each package. Also moved Test.pm to RepositoryTest.p…
jberger authored
7 $VERSION = eval $VERSION;
8
7eea0d4 @jberger Added A::B::PkgConfig and (some) tests for handling pc files
jberger authored
9 use Carp;
10 use File::Basename qw/fileparse/;
11
12 sub new {
13 my $class = shift;
9299e04 @jberger generate a _manual A::B::PC object from alien_provides_* rather than …
jberger authored
14
15 # allow creation of an object from a full spec.
16 if (ref $_[0] eq 'HASH') {
17 return bless $_[0], $class;
18 }
19
7eea0d4 @jberger Added A::B::PkgConfig and (some) tests for handling pc files
jberger authored
20 my ($path) = @_;
21 croak "Must specify a file" unless defined $path;
22
23 my $name = fileparse $path, '.pc';
24
25 my $self = {
26 package => $name,
27 vars => {},
28 keywords => {},
29 };
30
31 bless $self, $class;
32
33 $self->read($path);
34
35 return $self;
36 }
37
38 sub read {
39 my $self = shift;
40 my ($path) = @_;
41
42 open my $fh, '<', $path
43 or croak "Cannot open .pc file $path: $!";
44
45 while (<$fh>) {
46 if (/(.*?)=(.*)/) {
47 $self->{vars}{$1} = $2;
735c3cf @jberger space optional between key and value in keywords
jberger authored
48 } elsif (/^(.*?):\s*(.*)/) {
098d453 @jberger A::B::PC no longer splits on whitespace. More complexity than needed
jberger authored
49 $self->{keywords}{$1} = $2;
7eea0d4 @jberger Added A::B::PkgConfig and (some) tests for handling pc files
jberger authored
50 }
51 }
52 }
53
03a2136 @jberger vars getter/setter for A::B::PkgConfig
jberger authored
54 # getter/setter for vars
55 sub var {
56 my $self = shift;
57 my ($var, $newval) = @_;
58 if (defined $newval) {
59 $self->{vars}{$var} = $newval;
60 }
61 return $self->{vars}{$var};
62 }
63
96a5cf3 @jberger PkgConfig can now further abstract strings to variables
jberger authored
64 # abstract keywords and other vars in terms of "pure" vars
65 sub make_abstract {
66 my $self = shift;
8e4f5a0 @jberger Attempts to change the pkgconfig info to reflect the state of dist_dir
jberger authored
67 my ($top_var, $top_val) = @_;
68
96a5cf3 @jberger PkgConfig can now further abstract strings to variables
jberger authored
69 my @vars =
70 sort { length $self->{vars}{$b} <=> length $self->{vars}{$a} }
71 grep { $self->{vars}{$_} !~ /\$\{.*?\}/ } # skip vars which contain vars
72 keys %{ $self->{vars} };
73
8e4f5a0 @jberger Attempts to change the pkgconfig info to reflect the state of dist_dir
jberger authored
74 if ($top_var) {
75 @vars = grep { $_ ne $top_var } @vars;
3d0ce16 @jberger Getting closer to proper testing of build process. Problem now is lin…
jberger authored
76 unshift @vars, $top_var;
8e4f5a0 @jberger Attempts to change the pkgconfig info to reflect the state of dist_dir
jberger authored
77
78 $self->{vars}{$top_var} = $top_val if defined $top_val;
79 }
80
96a5cf3 @jberger PkgConfig can now further abstract strings to variables
jberger authored
81 foreach my $var (@vars) {
82 my $value = $self->{vars}{$var};
83 next if $value =~ /\$\{.*?\}/; # skip vars which contain vars
84
85 # convert other vars
86 foreach my $key (keys %{ $self->{vars} }) {
87 next if $key eq $var; # don't overwrite the current var
88 $self->{vars}{$key} =~ s/$value/\$\{$var\}/g;
89 }
90
098d453 @jberger A::B::PC no longer splits on whitespace. More complexity than needed
jberger authored
91 # convert keywords
96a5cf3 @jberger PkgConfig can now further abstract strings to variables
jberger authored
92 foreach my $key (keys %{ $self->{keywords} }) {
098d453 @jberger A::B::PC no longer splits on whitespace. More complexity than needed
jberger authored
93 $self->{keywords}{$key} =~ s/$value/\$\{$var\}/g;
96a5cf3 @jberger PkgConfig can now further abstract strings to variables
jberger authored
94 }
95 }
96 }
97
e6508ab @jberger A::B::PC can access keywords and interpolate variables into them
jberger authored
98 sub _interpolate_vars {
99 my $self = shift;
740e970 @jberger keyword method can now take a hashref of overrides for variable inter…
jberger authored
100 my ($string, $override) = @_;
e6508ab @jberger A::B::PC can access keywords and interpolate variables into them
jberger authored
101
b798b60 @jberger Include a warning on a pkg-config override variable whose value is fa…
jberger authored
102 $override ||= {};
103
104 foreach my $key (keys %$override) {
105 carp "Overriden pkg-config variable $key, contains no data"
106 unless $override->{$key};
107 }
108
740e970 @jberger keyword method can now take a hashref of overrides for variable inter…
jberger authored
109 1 while $string =~ s/\$\{(.*?)\}/$override->{$1} || $self->{vars}{$1}/e;
e6508ab @jberger A::B::PC can access keywords and interpolate variables into them
jberger authored
110
111 return $string;
112 }
113
114 sub keyword {
115 my $self = shift;
740e970 @jberger keyword method can now take a hashref of overrides for variable inter…
jberger authored
116 my ($keyword, $override) = @_;
117
118 {
119 no warnings 'uninitialized';
120 croak "overrides passed to 'keyword' must be a hashref"
121 if defined $override and ref $override ne 'HASH';
122 }
123
124 return $self->_interpolate_vars( $self->{keywords}{$keyword}, $override );
e6508ab @jberger A::B::PC can access keywords and interpolate variables into them
jberger authored
125 }
126
7eea0d4 @jberger Added A::B::PkgConfig and (some) tests for handling pc files
jberger authored
127 1;
128
Something went wrong with that request. Please try again.