File Coverage

blib/lib/PkgConfig/LibPkgConf/Package.pm
Criterion Covered Total %
statement 35 35 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod 9 9 100.0
total 56 56 100.0


line stmt bran cond sub pod time code
1             package PkgConfig::LibPkgConf::Package;
2              
3 4     4   124422 use strict;
  4         29  
  4         130  
4 4     4   22 use warnings;
  4         7  
  4         102  
5 4     4   405 use PkgConfig::LibPkgConf::XS;
  4         9  
  4         1964  
6              
7             our $VERSION = '0.11';
8              
9             =head1 NAME
10              
11             PkgConfig::LibPkgConf::Package - Represents a package
12              
13             =head1 SYNOPSIS
14              
15             use PkgConfig::LibPkgConf::Client;
16            
17             my $client = PkgConfig::LibPkgConf::Client->new;
18             $client->env;
19            
20             my $pkg = $client->find('libarchive');
21            
22             # use with system in scalar form:
23             my $cflags = $pkg->cflags;
24             my $libs = $pkg->libs;
25             system "$cc $cflags foo.c";
26             system "$cc -o foo foo.o $libs";
27            
28             # use with system in list form:
29             my @cflags = $pkg->list_cflags;
30             my @libs = $pkg->list_libs;
31             system $cc, @cflags, 'foo.c';
32             system $cc, -p => 'foo', 'foo.o', @libs;
33              
34             =head1 DESCRIPTION
35              
36             The L object stores package information. Part
37             of the package information is the compiler and linker flags. This can be fetched
38             as strings with C and C and as a list with C and
39             C. In the string form, escapes are retained, but in list form the
40             white space escapes are converted into spaces. That means if you are using the
41             string form of C/C you should use the string accessors, and if you
42             are using the list form of C/C you should use the list accessors.
43              
44             =head1 ATTRIBUTES
45              
46             =head2 refcount
47              
48             Internal reference count used by C.
49              
50             =head2 id
51              
52             The id of the package.
53              
54             =head2 filename
55              
56             The filename of the C<.pc> file.
57              
58             =head2 realname
59              
60             The real name for the package.
61              
62             =head2 version
63              
64             The version of the package.
65              
66             =head2 description
67              
68             Description of the package.
69              
70             =head2 url
71              
72             URL for the package.
73              
74             =head2 pc_filedir
75              
76             TODO
77              
78             =head1 METHODS
79              
80             =head2 libs
81              
82             Library flags. This usually includes things like C<-L/foo/lib> and C<-lfoo>.
83              
84             =cut
85              
86             sub libs
87             {
88 8     8 1 7740 my($self) = @_;
89 8         265 $self->_get_string($self->{client}, 0);
90             }
91              
92             =head2 libs_static
93              
94             Static library flags.
95              
96             =cut
97              
98             sub libs_static
99             {
100 4     4 1 14 my($self) = @_;
101 4         75 $self->_get_string($self->{client}, 1);
102             }
103              
104             =head2 cflags
105              
106             Compiler flags. This usually includes things like C<-I/foo/include> and C<-DFOO=1>.
107              
108             =cut
109              
110             sub cflags
111             {
112 9     9 1 27 my($self) = @_;
113 9         170 $self->_get_string($self->{client}, 2);
114             }
115              
116             =head2 cflags_static
117              
118             Static compiler flags.
119              
120             =cut
121              
122             sub cflags_static
123             {
124 6     6 1 14 my($self) = @_;
125 6         149 $self->_get_string($self->{client}, 3);
126             }
127              
128             =head2 list_libs
129              
130             my @fragments = $package->list_libs;
131              
132             Library flags as a list of fragments L. This is similar
133             to the C method above, but since it returns a list instead of a single string, it can
134             be used to filter for specific flags. For example:
135              
136             # equivalent to pkgconf --libs-only-L
137             my @lib_dirs = grep { $_->type eq 'L' } $package->list_libs;
138             # equivalent to pkgconf --libs-only-l
139             my @libs = grep { $_->type eq 'l' } $package->list_libs;
140              
141             =cut
142              
143             sub list_libs
144             {
145 4     4 1 968 my($self) = @_;
146 4         505 require PkgConfig::LibPkgConf::Fragment;
147 4         88 map { bless $_, 'PkgConfig::LibPkgConf::Fragment' } $self->_get_list($self->{client}, 0);
  11         39  
148             }
149              
150             =head2 list_libs_static
151              
152             my @fragments = $package->list_libs_static;
153              
154             Similar to C, but for the static libs flags.
155              
156             =cut
157              
158             sub list_libs_static
159             {
160 1     1 1 7 my($self) = @_;
161 1         8 require PkgConfig::LibPkgConf::Fragment;
162 1         20 map { bless $_, 'PkgConfig::LibPkgConf::Fragment' } $self->_get_list($self->{client}, 1);
  4         24  
163             }
164              
165             =head2 list_cflags
166              
167             my @fragments = $package->list_cflags;
168              
169             Compiler flags as a list of fragments L. This is similar
170             to the C method above, but since it returns a list instead of a single string, it
171             can be used to filter for specific flags. For example:
172              
173             # equivalent to pkgconf --cflags-only-I
174             my @include_dirs = grep { $_->type eq 'I' } $package->list_cflags;
175             # equivalent to pkgconf --cflags-only-other
176             my @other_cflags = grep { $_->type ne 'I' } $package->list_cflags;
177              
178             =cut
179              
180             sub list_cflags
181             {
182 4     4 1 15 my($self) = @_;
183 4         21 require PkgConfig::LibPkgConf::Fragment;
184 4         57 map { bless $_, 'PkgConfig::LibPkgConf::Fragment' } $self->_get_list($self->{client}, 2);
  9         29  
185             }
186              
187             =head2 list_cflags_static
188              
189             my @fragments = $package->list_cflags_static;
190              
191             Similar to C, but for the static compiler flags.
192              
193             =cut
194              
195             sub list_cflags_static
196             {
197 3     3 1 13 my($self) = @_;
198 3         13 require PkgConfig::LibPkgConf::Fragment;
199 3         52 map { bless $_, 'PkgConfig::LibPkgConf::Fragment' } $self->_get_list($self->{client}, 3);
  10         30  
200             }
201              
202             =head2 variable
203              
204             my $value = $package->variable($key);
205              
206             Look up the value for the given variable. Returns the value if found,
207             otherwise it will return undef (technically empty list).
208              
209             =cut
210              
211             sub variable
212             {
213 4     4 1 13 my($self, $name) = @_;
214 4         35 $self->_get_variable($name);
215             }
216              
217             =head1 SUPPORT
218              
219             IRC #native on irc.perl.org
220              
221             Project GitHub tracker:
222              
223             L
224              
225             If you want to contribute, please open a pull request on GitHub:
226              
227             L
228              
229             =head1 SEE ALSO
230              
231             For additional related modules, see L
232              
233             =head1 AUTHOR
234              
235             Graham Ollis
236              
237             For additional contributors see L
238              
239             =head1 COPYRIGHT AND LICENSE
240              
241             This software is copyright (c) 2016 Graham Ollis.
242              
243             This is free software; you may redistribute it and/or modify it under
244             the same terms as the Perl 5 programming language system itself.
245              
246             =cut
247            
248             1;