[perl-ExtUtils-PkgConfig] add exists method



commit eab78d0c7f4b9c0f39940418a9e887482462d917
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.

 lib/ExtUtils/PkgConfig.pm |   16 ++++++++++++++++
 t/1.t                     |    8 +++++++-
 2 files changed, 23 insertions(+), 1 deletions(-)
---
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 9d15677..bfd93a4 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/) );


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]