File Coverage

blib/lib/Alien/FFI.pm
Criterion Covered Total %
statement 15 31 48.3
branch 0 4 0.0
condition n/a
subroutine 6 13 46.1
pod n/a
total 21 48 43.7


line stmt bran cond sub pod time code
1             package Alien::FFI;
2              
3 3     3   463952 use strict;
  3         4  
  3         85  
4 3     3   12 use warnings;
  3         4  
  3         94  
5 3     3   74 use 5.008001;
  3         7  
6 3     3   14 use Carp qw( croak );
  3         3  
  3         1225  
7              
8             # ABSTRACT: Get libffi compiler and linker flags
9             our $VERSION = '0.15_01'; # TRIAL VERSION
10              
11              
12             sub new
13             {
14 0     0     my($class) = @_;
15 0           bless {}, $class;
16             }
17              
18             my $pkg_config;
19              
20             foreach my $try ($ENV{PKG_CONFIG}, 'pkg-config', 'pkgconf')
21             {
22             next unless defined $try;
23             require IPC::Cmd;
24             if(IPC::Cmd::can_run($try))
25             {
26             $pkg_config = $try;
27             last;
28             }
29             }
30              
31             unless($pkg_config)
32             {
33 3     3   693 if(eval q{ use PkgConfig (); 1 })
  0            
  0            
34             {
35             $pkg_config = "$^X $INC{'PkgConfig.pm'}";
36             }
37             }
38              
39             unless($pkg_config)
40             {
41             die "unable to find pkg-config, pkgconf or PkgConfig.pm";
42             }
43              
44             sub install_type
45             {
46 0     0     'system';
47             }
48              
49             my $config;
50              
51             sub config
52             {
53 0     0     my(undef, $key) = @_;
54              
55 0 0         unless($config)
56             {
57 0           my $version = `$pkg_config --modversion libffi`;
58 0 0         die "package libffi not found" if $?;
59 0           chomp $version;
60 0           $config = {
61             version => $version,
62             pkg_config => $pkg_config,
63             };
64             }
65            
66 0           $config->{$key};
67             }
68              
69             foreach my $linkage ('share','static')
70             {
71             foreach my $name ('cflags','libs')
72             {
73             my $value;
74            
75             my $flags = "--$name";
76             my $subname = $name;
77             if($linkage eq 'static')
78             {
79             $flags .= ' --static' if $linkage eq 'static';
80             $subname .= '_static' if $linkage
81             }
82            
83             my $sub = sub {
84             unless(defined $value)
85             {
86             print "command = $pkg_config $flags libffi\n";
87             $value = `$pkg_config $flags libffi`;
88             die "package libffi not found" if $?;
89             chomp $value;
90             }
91             $value;
92             };
93              
94 3     3   15 no strict 'refs';
  3         5  
  3         373  
95             *$subname = $sub;
96             }
97             }
98              
99             sub dist_dir
100             {
101 0     0     croak "Failed to find share dir for dist 'Alt-Alien-FFI-System'";
102             }
103              
104 0     0     sub bin_dir { () }
105 0     0     sub dynamic_libs { () }
106 0     0     sub version { shift->config('version') }
107              
108             1;
109              
110             __END__