File Coverage

blib/lib/PkgConfig/LibPkgConf.pm
Criterion Covered Total %
statement 28 28 100.0
branch 2 2 100.0
condition n/a
subroutine 10 10 100.0
pod 6 6 100.0
total 46 46 100.0


line stmt bran cond sub pod time code
1             package PkgConfig::LibPkgConf;
2              
3 2     2   81567 use strict;
  2         14  
  2         52  
4 2     2   9 use warnings;
  2         3  
  2         52  
5 2     2   42 use base qw( Exporter );
  2         4  
  2         835  
6              
7             our $VERSION = '0.10';
8             our @EXPORT = qw(
9             pkgconf_cflags
10             pkgconf_libs
11             pkgconf_exists
12             pkgconf_version
13             pkgconf_cflags_static
14             pkgconf_libs_static
15             );
16              
17             =head1 NAME
18              
19             PkgConfig::LibPkgConf - Interface to .pc file interface via libpkgconf
20              
21             =head1 SYNOPSIS
22              
23             use PkgConfig::LibPkgConf;
24            
25             if(pkgconf_exists('libarchive'))
26             {
27             my $version = pkgconf_version('libarchive');
28             my $cflags = pkgconf_cflags('libarchive');
29             my $libs = pkgconf_libs('libarchive');
30             }
31              
32             =head1 DESCRIPTION
33              
34             Many libraries in compiled languages such as C or C++ provide C<.pc>
35             files to specify the flags required for compiling and linking against
36             those libraries. Traditionally, the command line program C
37             is used to query these files. This module provides a Perl level API
38             using C to these files.
39              
40             This module provides a simplified interface for getting the existence,
41             version, cflags and library flags needed for compiling against a package,
42             using the default compiled in configuration of C. For a more
43             powerful, but complicated interface see L.
44             In addition, L provides some useful utility
45             functions that are also provided by C.
46              
47             =head1 FUNCTIONS
48              
49             =head2 pkgconf_exists
50              
51             my $bool = pkgconf_exists $package_name;
52              
53             Returns true if the package is available.
54              
55             Exported by default.
56              
57             =cut
58              
59             sub pkgconf_exists
60             {
61 2     2 1 1468 my $pkg = eval { _pkg($_[0]) };
  2         6  
62 2         26 return defined $pkg;
63             }
64              
65             =head2 pkgconf_version
66              
67             my $version = pkgconf_version $package_name;
68              
69             Returns the version of the package, if it exists. Will throw an exception
70             if not found.
71              
72             Exported by default.
73              
74             =cut
75              
76             sub pkgconf_version
77             {
78 2     2 1 6 my $pkg = _pkg($_[0]);
79 1         17 $pkg->version;
80             }
81              
82             =head2 pkgconf_cflags
83              
84             my $cflags = pkgconf_cflags $package_name;
85              
86             Returns the compiler flags for the package, if it exists. Will throw an
87             exception if not found.
88              
89             Exported by default.
90              
91             =cut
92              
93             sub pkgconf_cflags
94             {
95 2     2 1 607 my $pkg = _pkg($_[0]);
96 1         6 $pkg->cflags;
97             }
98              
99             =head2 pkgconf_cflags_static
100              
101             my $cflags = pkgconf_cflags_static $package_name;
102              
103             Returns the static compiler flags for the package, if it exists. Will throw
104             an exception if not found.
105              
106             =cut
107              
108             sub pkgconf_cflags_static
109             {
110 1     1 1 3510 my $pkg = _pkg($_[0]);
111 1         9 $pkg->cflags_static;
112             }
113              
114             =head2 pkgconf_libs
115              
116             my $libs = pkgconf_libs $package_name;
117              
118             Returns the linker library flags for the package, if it exists. Will throw
119             an exception if not found.
120              
121             Exported by default.
122              
123             =cut
124              
125             sub pkgconf_libs
126             {
127 2     2 1 623 my $pkg = _pkg($_[0]);
128 1         5 $pkg->libs;
129             }
130              
131             =head2 pkgconf_libs_static
132              
133             my $libs = pkgconf_libs_static $package_name;
134              
135             Returns the static linker library flags for the package, if it exists. Will
136             throw an exception if not found.
137              
138             =cut
139              
140             sub pkgconf_libs_static
141             {
142 1     1 1 3 my $pkg = _pkg($_[0]);
143 1         5 $DB::single = 1;
144 1         4 $pkg->libs_static;
145             }
146              
147             sub _pkg
148             {
149 10     10   22 my($name) = @_;
150 10         546 require PkgConfig::LibPkgConf::Client;
151 10         32 my $pkg = PkgConfig::LibPkgConf::Client->new->find($name);
152 10 100       85 die "package $name not found" unless $pkg;
153 6         11 $pkg;
154             }
155              
156             1;
157              
158             =head1 SUPPORT
159              
160             IRC #native on irc.perl.org
161              
162             Project GitHub tracker:
163              
164             L
165              
166             If you want to contribute, please open a pull request on GitHub:
167              
168             L
169              
170             =head1 SEE ALSO
171              
172             The best entry point to the low level C interface can be found
173             via L.
174              
175             Alternatives include:
176              
177             =over 4
178              
179             =item L
180              
181             Pure Perl implementation of C which can be used from the
182             command line, or as an API from Perl. Does not require pkg-config in
183             your path, so is a safe dependency for CPAN modules.
184              
185             =item L
186              
187             Wrapper for the C command line interface. This module will
188             fail to install if C cannot be found in the C, so it
189             is not safe to use a dependency if you want your CPAN module to work on
190             platforms where C is not installed.
191              
192             =item L
193              
194             Provides tools for building non-Perl libraries and making them
195             dependencies for your CPAN modules, even on platforms where the non-Perl
196             libraries aren't already installed. Includes hooks for probing
197             C C<.pc> files using either C or L.
198              
199             =back
200              
201             =head1 ACKNOWLEDGMENTS
202              
203             Thanks to the C developers for their efforts:
204              
205             L
206              
207             =head1 AUTHOR
208              
209             Graham Ollis
210              
211             Contributors:
212              
213             A. Wilcox (awilfox)
214              
215             Petr Pisar (ppisar)
216              
217             =head1 COPYRIGHT AND LICENSE
218              
219             This software is copyright (c) 2016 Graham Ollis.
220              
221             This is free software; you may redistribute it and/or modify it under
222             the same terms as the Perl 5 programming language system itself.
223              
224             =cut