File Coverage

blib/lib/ExtUtils/Builder/Profile/Perl.pm
Criterion Covered Total %
statement 39 58 67.2
branch 4 12 33.3
condition 7 28 25.0
subroutine 10 12 83.3
pod 0 2 0.0
total 60 112 53.5


line stmt bran cond sub pod time code
1             package ExtUtils::Builder::Profile::Perl;
2             $ExtUtils::Builder::Profile::Perl::VERSION = '0.036';
3 1     1   385 use strict;
  1         2  
  1         27  
4 1     1   17 use warnings;
  1         1  
  1         45  
5              
6 1     1   4 use ExtUtils::Builder::Util 0.018 'split_like_shell';
  1         14  
  1         52  
7 1     1   4 use File::Basename 'dirname';
  1         2  
  1         34  
8 1     1   3 use File::Spec::Functions qw/catdir/;
  1         1  
  1         721  
9              
10             sub _get_var {
11 4     4   5 my ($config, $opts, $key) = @_;
12 4   33     14 return delete $opts->{$key} // $config->get($key);
13             }
14              
15             sub _split_var {
16 3     3   5 my ($config, $opts, $key) = @_;
17 3   50     11 return delete $opts->{$key} // [ split_like_shell($config->get($key)) ];
18             }
19              
20             sub process_compiler {
21 1     1 0 3 my ($class, $compiler, $opts) = @_;
22 1         2 my $config = delete $opts->{config};
23 1         17 my $incdir = catdir(_get_var($config, $opts, 'archlibexp'), 'CORE');
24 1         18 my $os = _get_var($config, $opts, 'osname');
25 1         8 my $osver = _get_var($config, $opts, 'osvers');
26 1         8 my ($osmajor) = $osver =~ /^(\d+)/;
27 1 50 33     4 if ($os eq 'darwin' && $^X eq '/usr/bin/perl' && $osmajor >= 18) {
      33        
28 0         0 $compiler->add_argument(value => [ '-iwithsysroot', $incdir ], ranking => $compiler->default_include_ranking + 1);
29             } else {
30 1     1   10 $compiler->add_include_dirs([$incdir], ranking => sub { $_[0] + 1 });
  1         2  
31             }
32 1         4 $compiler->add_argument(ranking => 60, value => _split_var($config, $opts, 'ccflags'));
33 1         3 $compiler->add_argument(ranking => 65, value => _split_var($config, $opts, 'optimize'));
34 1         4 return;
35             }
36              
37             my $rpath_regex = qr/ ( (?
38              
39             my %needs_relinking = map { $_ => 1 } qw/MSWin32 cygwin aix VMS/;
40              
41             sub process_linker {
42 1     1 0 2 my ($class, $linker, $opts) = @_;
43 1         2 my $config = delete $opts->{config};
44 1         2 $linker->add_argument(ranking => 60, value => _split_var($config, $opts, 'ldflags'));
45 1 50       5 if ($linker->export eq 'some') {
46             $linker->add_option_filter(sub {
47 0     0   0 my ($self, $from, $to, %opts) = @_;
48 0 0 0     0 $opts{dl_name} //= $opts{module_name} if $opts{module_name};
49 0   0     0 $opts{dl_file} //= do {
50 0         0 (my $short = $opts{dl_name}) =~ s/.*:://;
51 0         0 catdir(dirname($to), "$short");
52             };
53 0         0 return ($from, $to, %opts);
54 0         0 });
55             }
56 1         2 my $os = _get_var($config, $opts, 'osname');
57 1 50 33     12 if ($linker->type eq 'executable' or $linker->type eq 'shared-library' or ($linker->type eq 'loadable-object' and $needs_relinking{$os})) {
      33        
      33        
58 0         0 my ($libperl, $libext, $so) = map { _get_var($config, $opts, $_) } qw/libperl lib_ext so/;
  0         0  
59 0         0 my ($lib) = $libperl =~ / \A (?:lib)? ( \w* perl \w* ) (?: \. $so | $libext) \b /msx;
60 0     0   0 $linker->add_libraries([$lib], ranking => sub { $_[0] - 1 });
  0         0  
61              
62 0         0 my $libdir = catdir(_get_var($config, $opts, 'archlibexp'), 'CORE');
63 0         0 $linker->add_library_dirs([$libdir]);
64 0         0 $linker->add_argument(ranking => 80, value => _split_var($config, $opts, 'perllibs'));
65             }
66 1 50       2 if ($linker->type eq 'executable') {
67 0   0     0 my $rpath = $opts->{rpath} // [ split_like_shell($config->get('ccdlflags') =~ $rpath_regex) ];
68 0 0       0 $linker->add_argument(ranking => 40, value => $rpath) if @{$rpath};
  0         0  
69             }
70 1         4 return;
71             }
72              
73             1;
74              
75             # ABSTRACT: A profile for compiling and linking against perl
76              
77             __END__