blib/lib/Dist/Build/XS/Alien.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 93 CC 10 SCAR 43.0
CC
10
Cov
0%
add_methods
110.0
BEGIN
2.0
BEGIN
2.0
CRAP 74.0
1 package Dist::Build::XS::Alien;
2 $Dist::Build::XS::Alien::VERSION = '0.028';
3 use strict;
4 use warnings;
5  
6 use parent 'ExtUtils::Builder::Planner::Extension';
7  
8 use Carp 'croak';
9 use ExtUtils::Builder::Util 0.018 qw/require_module split_like_shell/;
10  
11 sub add_methods {
12 my ($self, $planner, %args) = @_;
13  
14 my $add_xs = $planner->can('add_xs') or croak 'XS must be loaded before imports can be done';
15  
16 $planner->add_delegate('add_xs', sub {
17 my ($planner, %args) = @_;
18  
19 if (my $alien = delete $args{alien} // delete $args{external}) {
20 my @aliens = ref $alien ? @{ $alien } : $alien;
21  
22 for my $alien (@aliens) {
23 my $module = $alien =~ /::/ ? $alien : "Alien::$alien";
24 require_module($module);
25  
26 my $use_static = $module->install_type eq 'share' && $module->can('cflags_static');
27 my ($cflags, $ldflags) = $use_static ? ($module->cflags_static, $module->libs_static) : ($module->cflags, $module->libs);
28  
29 for my $compiler_flag (split_like_shell($cflags)) {
30 if ($compiler_flag =~ s/^-I//) {
31 unshift @{ $args{include_dirs} }, $compiler_flag;
32 } elsif ($compiler_flag =~ /^-D(\w+)=(.*)/) {
33 $args{defines}{$1} //= $2;
34 } elsif ($compiler_flag =~ /^-D(\w+)/) {
35 $args{defines}{$1} //= '';
36 } else {
37 unshift @{ $args{extra_compiler_flags} }, $compiler_flag;
38 }
39 }
40  
41 for my $linker_flag (split_like_shell($ldflags)) {
42 if ($linker_flag =~ s/^-l//) {
43 unshift @{ $args{libraries} }, $linker_flag;
44 } elsif ($linker_flag =~ s/^-L//) {
45 unshift @{ $args{library_dirs} }, $linker_flag;
46 } else {
47 unshift @{ $args{extra_linker_flags} }, $linker_flag;
48 }
49 }
50 }
51 }
52  
53 $planner->$add_xs(%args);
54 });
55 }
56  
57 1;
58  
59 # ABSTRACT: Dist::Build extension to use Alien modules.
60  
61 __END__