Skip Menu |

This queue is for tickets about the ExtUtils-PkgConfig CPAN distribution.

Report information
The Basics
Id: 119420
Status: resolved
Priority: 0/
Queue: ExtUtils-PkgConfig

People
Owner: Nobody in particular
Requestors: PLICEASE [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Query method for existence of a package
Please add a method for determining if a package is installed. I am attaching a patch which would implement this proposed method. I also have a fork of your repository here: https://github.com/plicease/ExtUtils-PkgConfig/commits/exists This would also alleviate rt#778800, since the caller can check if the package exists, before trying to probe for other fields. Thank you for your consideration.
Subject: exists.diff
commit 7a47360387194f9ea247abbf590ea169edb5d243 Author: Graham Ollis <plicease@cpan.org> Date: Fri Dec 23 13:27:34 2016 -0500 add exists method This will help resolve rt#77880, in that it would allow the caller to check first to see if the package he/she is interested in is available. This is useful for optional prereqs, for which you do not want noisy diagnostics when they are not found. diff --git a/lib/ExtUtils/PkgConfig.pm b/lib/ExtUtils/PkgConfig.pm index 09ede40..7836d59 100644 --- a/lib/ExtUtils/PkgConfig.pm +++ b/lib/ExtUtils/PkgConfig.pm @@ -84,6 +84,20 @@ sub AUTOLOAD return $ans; } +sub exists { + my ($class, @pkg_candidates) = @_; + + foreach my $candidate (@pkg_candidates) + { + my $output = qx/pkg-config --exists "$candidate" 2>&1/; + if (0 == $CHILD_ERROR) { + return 1; + } + } + + return ''; +} + sub find { my ($class, @pkg_candidates) = @_; my (@pkgs_found, @error_messages); @@ -203,6 +217,8 @@ ExtUtils::PkgConfig - simplistic interface to pkg-config print "cflags: $pkg_info{cflags}\n"; print "libs: $pkg_info{libs}\n"; + $exists = ExtUtils::PkgConfig->exists($package); + $modversion = ExtUtils::PkgConfig->modversion($package); $libs = ExtUtils::PkgConfig->libs($package); diff --git a/t/1.t b/t/1.t index 5306d37..e548e31 100644 --- a/t/1.t +++ b/t/1.t @@ -7,7 +7,7 @@ use warnings; ######################### -use Test::More tests => 7; +use Test::More tests => 10; BEGIN { use_ok('ExtUtils::PkgConfig') }; require 't/swallow_stderr.inc'; @@ -32,13 +32,19 @@ swallow_stderr (sub { ok( $@ ); }); +ok( ExtUtils::PkgConfig->exists(qw/test_glib-2.0 /) ); + # test 2 for success eval { %pkg = ExtUtils::PkgConfig->find(qw/bad1 test_glib-2.0/); }; ok( not $@ ); ok( $pkg{modversion} and $pkg{cflags} and $pkg{libs} ); +ok( ExtUtils::PkgConfig->exists(qw/bad1 test_glib-2.0/) ); + # test 2 for failure swallow_stderr (sub { eval { %pkg = ExtUtils::PkgConfig->find(qw/bad1 bad2/); }; ok( $@ ); }); + +ok( !ExtUtils::PkgConfig->exists(qw/bad1 bad2/) );
Thanks a lot for the well done patch. Committed to our repository.