blib/lib/PkgConfig/LibPkgConf.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 6 / 6 totaltotal 100% 49 / 49 CC 2 SCAR 1.7
CC
2
Cov
100%
_pkg
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« blib/lib/PkgConfig/LibPkgConf/Fragment.pm ↑ Summary LibPkgConf.xs »
1 package PkgConfig::LibPkgConf;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.11';
8 2 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<pkg-config>
37 is used to query these files. This module provides a Perl level API
38 using C<libpkgconf> 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<pkgconf>. For a more
43 powerful, but complicated interface see L<PkgConfig::LibPkgConf::Client>.
44 In addition, L<PkgConfig::LibPkgConf::Util> provides some useful utility
45 functions that are also provided by C<pkgconf>.
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 2 ▶{
Subroutine pkgconf_exists: called CC=1 SCAR=0.0
Pod documented
61 2 my $pkg = eval { _pkg($_[0]) };
62 2 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 2 ▶{
Subroutine pkgconf_version: called CC=1 SCAR=0.0
Pod documented
78 2 my $pkg = _pkg($_[0]);
79 1 $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 2 ▶{
Subroutine pkgconf_cflags: called CC=1 SCAR=0.0
Pod documented
95 2 my $pkg = _pkg($_[0]);
96 1 $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 1 ▶{
Subroutine pkgconf_cflags_static: called CC=1 SCAR=0.0
Pod documented
110 1 my $pkg = _pkg($_[0]);
111 1 $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 2 ▶{
Subroutine pkgconf_libs: called CC=1 SCAR=0.0
Pod documented
127 2 my $pkg = _pkg($_[0]);
128 1 $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 1 ▶{
Subroutine pkgconf_libs_static: called CC=1 SCAR=0.0
Pod documented
142 1 my $pkg = _pkg($_[0]);
143 1 $DB::single = 1;
144 1 $pkg->libs_static;
145 }
146  
147 sub _pkg
148 10 ▶{
Subroutine _pkg: called CC=2 SCAR=6.9
149 10 my($name) = @_;
150 10 require PkgConfig::LibPkgConf::Client;
151 10 my $pkg = PkgConfig::LibPkgConf::Client->new->find($name);
152 10 ▶ die "package $name not found" unless $pkg;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg 4 6 10
153 6 $pkg;
154 }
155  
156 2 1;
157  
158 =head1 SUPPORT
159  
160 IRC #native on irc.perl.org
161  
162 Project GitHub tracker:
163  
164 L<https://github.com/plicease/PkgConfig-LibPkgConf/issues>
165  
166 If you want to contribute, please open a pull request on GitHub:
167  
168 L<https://github.com/plicease/PkgConfig-LibPkgConf/pulls>
169  
170 =head1 SEE ALSO
171  
172 The best entry point to the low level C<pkgconf> interface can be found
173 via L<PkgConfig::LibPkgConf::Client>.
174  
175 Alternatives include:
176  
177 =over 4
178  
179 =item L<PkgConfig>
180  
181 Pure Perl implementation of C<pkg-config> 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<ExtUtils::PkgConfig>
186  
187 Wrapper for the C<pkg-config> command line interface. This module will
188 fail to install if C<pkg-config> cannot be found in the C<PATH>, so it
189 is not safe to use a dependency if you want your CPAN module to work on
190 platforms where C<pkg-config> is not installed.
191  
192 =item L<Alien::Base>
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<pkg-config> C<.pc> files using either C<pkg-config> or L<PkgConfig>.
198  
199 =back
200  
201 =head1 ACKNOWLEDGMENTS
202  
203 Thanks to the C<pkgconf> developers for their efforts:
204  
205 L<https://github.com/pkgconf/pkgconf/graphs/contributors>
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
« blib/lib/PkgConfig/LibPkgConf/Fragment.pm ↑ Summary LibPkgConf.xs »