File Coverage

blib/lib/Alien/Build/Plugin/PkgConfig/Negotiate.pm
Criterion Covered Total %
statement 52 53 98.1
branch 15 16 93.7
condition 11 12 91.6
subroutine 11 11 100.0
pod 2 2 100.0
total 91 94 96.8


line stmt bran cond sub pod time code
1             package Alien::Build::Plugin::PkgConfig::Negotiate;
2              
3 6     6   247960 use strict;
  6         28  
  6         233  
4 6     6   35 use warnings;
  6         12  
  6         309  
5 6     6   127 use 5.008004;
  6         24  
6 6     6   913 use Alien::Build::Plugin;
  6         17  
  6         41  
7 6     6   2192 use Alien::Build::Plugin::PkgConfig::PP;
  6         19  
  6         68  
8 6     6   2180 use Alien::Build::Plugin::PkgConfig::LibPkgConf;
  6         18  
  6         50  
9 6     6   2149 use Alien::Build::Plugin::PkgConfig::CommandLine;
  6         27  
  6         46  
10 6     6   552 use Alien::Build::Util qw( _perl_config );
  6         18  
  6         328  
11 6     6   44 use Carp ();
  6         14  
  6         2741  
12              
13             # ABSTRACT: Package configuration negotiation plugin
14             our $VERSION = '2.46'; # 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 56362 my($class) = @_;
37              
38 28 100       124 return $ENV{ALIEN_BUILD_PKG_CONFIG} if $ENV{ALIEN_BUILD_PKG_CONFIG};
39              
40 21 100       158 if(Alien::Build::Plugin::PkgConfig::LibPkgConf->available)
41             {
42 1         13 return 'PkgConfig::LibPkgConf';
43             }
44              
45 20 100       704 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     4859 my $is_solaris64 = (_perl_config('osname') eq 'solaris' && _perl_config('ptrsize') == 8);
52              
53             # PkgConfig.pm is more reliable on windows
54 5         58 my $is_windows = _perl_config('osname') eq 'MSWin32';
55              
56 5 100 100     57 if(!$is_solaris64 && !$is_windows)
57             {
58 3         39 return 'PkgConfig::CommandLine';
59             }
60             }
61              
62 17 50       7818 if(Alien::Build::Plugin::PkgConfig::PP->available)
63             {
64 17         209 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 58 my($self, $meta) = @_;
80              
81 16         44 my $plugin = $self->pick;
82 16         140 Alien::Build->log("Using PkgConfig plugin: $plugin");
83              
84 16 100       2052 if(ref($self->pkg_name) eq 'ARRAY')
85             {
86 1         6 $meta->add_requires('configure', 'Alien::Build::Plugin::PkgConfig::Negotiate' => '0.79');
87             }
88              
89 16 100 100     60 if($self->atleast_version || $self->exact_version || $self->max_version)
      100        
90             {
91 3         10 $meta->add_requires('configure', 'Alien::Build::Plugin::PkgConfig::Negotiate' => '1.53');
92             }
93              
94 16         65 my @args;
95 16         51 push @args, pkg_name => $self->pkg_name;
96 16         43 push @args, register_prereqs => 0;
97              
98 16         45 foreach my $method (map { "${_}_version" } qw( minimum atleast exact max ))
  64         173  
99             {
100 64 100       164 push @args, $method => $self->$method if defined $self->$method;
101             }
102              
103 16         112 $meta->apply_plugin($plugin, @args);
104              
105 16         90 $self;
106             }
107              
108             1;
109              
110             __END__