| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Alien::Build::Plugin::PkgConfig::Negotiate; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 6 |  |  | 6 |  | 225137 | use strict; | 
|  | 6 |  |  |  |  | 23 |  | 
|  | 6 |  |  |  |  | 163 |  | 
| 4 | 6 |  |  | 6 |  | 29 | use warnings; | 
|  | 6 |  |  |  |  | 11 |  | 
|  | 6 |  |  |  |  | 201 |  | 
| 5 | 6 |  |  | 6 |  | 132 | use 5.008004; | 
|  | 6 |  |  |  |  | 20 |  | 
| 6 | 6 |  |  | 6 |  | 744 | use Alien::Build::Plugin; | 
|  | 6 |  |  |  |  | 15 |  | 
|  | 6 |  |  |  |  | 39 |  | 
| 7 | 6 |  |  | 6 |  | 2072 | use Alien::Build::Plugin::PkgConfig::PP; | 
|  | 6 |  |  |  |  | 18 |  | 
|  | 6 |  |  |  |  | 78 |  | 
| 8 | 6 |  |  | 6 |  | 2116 | use Alien::Build::Plugin::PkgConfig::LibPkgConf; | 
|  | 6 |  |  |  |  | 16 |  | 
|  | 6 |  |  |  |  | 47 |  | 
| 9 | 6 |  |  | 6 |  | 1780 | use Alien::Build::Plugin::PkgConfig::CommandLine; | 
|  | 6 |  |  |  |  | 17 |  | 
|  | 6 |  |  |  |  | 44 |  | 
| 10 | 6 |  |  | 6 |  | 568 | use Alien::Build::Util qw( _perl_config ); | 
|  | 6 |  |  |  |  | 17 |  | 
|  | 6 |  |  |  |  | 373 |  | 
| 11 | 6 |  |  | 6 |  | 34 | use Carp (); | 
|  | 6 |  |  |  |  | 16 |  | 
|  | 6 |  |  |  |  | 2504 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | # ABSTRACT: Package configuration negotiation plugin | 
| 14 |  |  |  |  |  |  | our $VERSION = '2.47'; # VERSION | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | has '+pkg_name' => sub { | 
| 18 |  |  |  |  |  |  | Carp::croak "pkg_name is a required property"; | 
| 19 |  |  |  |  |  |  | }; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | has atleast_version => undef; | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | has exact_version => undef; | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | has max_version => undef; | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | has minimum_version => undef; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | sub pick | 
| 35 |  |  |  |  |  |  | { | 
| 36 | 28 |  |  | 28 | 1 | 44277 | my($class) = @_; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 28 | 100 |  |  |  | 137 | return $ENV{ALIEN_BUILD_PKG_CONFIG} if $ENV{ALIEN_BUILD_PKG_CONFIG}; | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 21 | 100 |  |  |  | 143 | if(Alien::Build::Plugin::PkgConfig::LibPkgConf->available) | 
| 41 |  |  |  |  |  |  | { | 
| 42 | 1 |  |  |  |  | 7 | return 'PkgConfig::LibPkgConf'; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 20 | 100 |  |  |  | 568 | if(Alien::Build::Plugin::PkgConfig::CommandLine->available) | 
| 46 |  |  |  |  |  |  | { | 
| 47 |  |  |  |  |  |  | # TODO: determine environment or flags necessary for using pkg-config | 
| 48 |  |  |  |  |  |  | # on solaris 64 bit. | 
| 49 |  |  |  |  |  |  | # Some advice on pkg-config and 64 bit Solaris | 
| 50 |  |  |  |  |  |  | # https://docs.oracle.com/cd/E53394_01/html/E61689/gplhi.html | 
| 51 | 5 |  | 66 |  |  | 3830 | my $is_solaris64 = (_perl_config('osname') eq 'solaris' && _perl_config('ptrsize') == 8); | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | # PkgConfig.pm is more reliable on windows | 
| 54 | 5 |  |  |  |  | 55 | my $is_windows = _perl_config('osname') eq 'MSWin32'; | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 5 | 100 | 100 |  |  | 40 | if(!$is_solaris64 && !$is_windows) | 
| 57 |  |  |  |  |  |  | { | 
| 58 | 3 |  |  |  |  | 17 | return 'PkgConfig::CommandLine'; | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 17 | 50 |  |  |  | 6627 | if(Alien::Build::Plugin::PkgConfig::PP->available) | 
| 63 |  |  |  |  |  |  | { | 
| 64 | 17 |  |  |  |  | 186 | return 'PkgConfig::PP'; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  | else | 
| 67 |  |  |  |  |  |  | { | 
| 68 |  |  |  |  |  |  | # this is a fata error.  because we check for a pkg-config implementation | 
| 69 |  |  |  |  |  |  | # at configure time, we expect at least one of these to work.  (and we | 
| 70 |  |  |  |  |  |  | # fallback on installing PkgConfig.pm as a prereq if nothing else is avail). | 
| 71 |  |  |  |  |  |  | # we therefore expect at least one of these to work, if not, then the configuration | 
| 72 |  |  |  |  |  |  | # of the system has shifted from underneath us. | 
| 73 | 0 |  |  |  |  | 0 | Carp::croak("Could not find an appropriate pkg-config or pkgconf implementation, please install PkgConfig.pm, PkgConfig::LibPkgConf, pkg-config or pkgconf"); | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | sub init | 
| 78 |  |  |  |  |  |  | { | 
| 79 | 16 |  |  | 16 | 1 | 82 | my($self, $meta) = @_; | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 16 |  |  |  |  | 69 | my $plugin = $self->pick; | 
| 82 | 16 |  |  |  |  | 167 | Alien::Build->log("Using PkgConfig plugin: $plugin"); | 
| 83 |  |  |  |  |  |  |  | 
| 84 | 16 | 100 |  |  |  | 2750 | if(ref($self->pkg_name) eq 'ARRAY') | 
| 85 |  |  |  |  |  |  | { | 
| 86 | 1 |  |  |  |  | 7 | $meta->add_requires('configure', 'Alien::Build::Plugin::PkgConfig::Negotiate' => '0.79'); | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 | 16 | 100 | 100 |  |  | 72 | if($self->atleast_version || $self->exact_version || $self->max_version) | 
|  |  |  | 100 |  |  |  |  | 
| 90 |  |  |  |  |  |  | { | 
| 91 | 3 |  |  |  |  | 15 | $meta->add_requires('configure', 'Alien::Build::Plugin::PkgConfig::Negotiate' => '1.53'); | 
| 92 |  |  |  |  |  |  | } | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 16 |  |  |  |  | 76 | my @args; | 
| 95 | 16 |  |  |  |  | 45 | push @args, pkg_name         => $self->pkg_name; | 
| 96 | 16 |  |  |  |  | 43 | push @args, register_prereqs => 0; | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 16 |  |  |  |  | 48 | foreach my $method (map { "${_}_version" } qw( minimum atleast exact max )) | 
|  | 64 |  |  |  |  | 158 |  | 
| 99 |  |  |  |  |  |  | { | 
| 100 | 64 | 100 |  |  |  | 165 | push @args, $method => $self->$method if defined $self->$method; | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  |  | 
| 103 | 16 |  |  |  |  | 110 | $meta->apply_plugin($plugin, @args); | 
| 104 |  |  |  |  |  |  |  | 
| 105 | 16 |  |  |  |  | 101 | $self; | 
| 106 |  |  |  |  |  |  | } | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | 1; | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | __END__ |