File Coverage

blib/lib/ExtUtils/Builder/BuildTools/Base.pm
Criterion Covered Total %
statement 52 60 86.6
branch 12 20 60.0
condition 12 19 63.1
subroutine 16 16 100.0
pod 0 1 0.0
total 92 116 79.3


line stmt bran cond sub pod time code
1             package ExtUtils::Builder::BuildTools::Base;
2             $ExtUtils::Builder::BuildTools::Base::VERSION = '0.036';
3 2     2   973 use strict;
  2         3  
  2         98  
4 2     2   10 use warnings;
  2         3  
  2         100  
5              
6 2     2   9 use parent 'ExtUtils::Builder::Planner::Extension';
  2         3  
  2         11  
7              
8 2     2   1712 use Carp 'croak';
  2         5  
  2         158  
9 2     2   16 use File::Spec::Functions 'catfile';
  2         6  
  2         1454  
10              
11             sub add_methods {
12 2     2 0 275 my ($class, $planner, %opts) = @_;
13              
14 2   50     9 $opts{type} //= 'executable';
15              
16 2   50     16 my $compiler_as = delete $opts{compiler_as} // 'compile';
17             $planner->add_delegate($compiler_as, sub {
18 2     2   11 my ($planner, $from, $to, %extra) = @_;
        2      
19 2         8 my %args = (%opts, %extra);
20              
21 2         16 my $compiler = $class->make_compiler(\%args);
22              
23 2 100 66     12 $args{profiles} = [ delete $args{profile} ] if $args{profile} and not $args{profiles};
24 2   100     4 for my $profile (@{ $args{profiles} // [] }) {
  2         53  
25 1         6 $compiler->add_profile($profile, %args);
26             }
27              
28 2 50       7 if (my $include_dirs = $args{include_dirs}) {
29 0         0 $compiler->add_include_dirs($include_dirs);
30             }
31 2 50       6 if (my $defines = $args{defines}) {
32 0         0 $compiler->add_defines($defines);
33             }
34 2 50       7 if (my $extra = $args{extra_args}) {
35 0         0 $compiler->add_argument(value => $extra);
36             }
37 2 50       7 if (my $standard = $args{standard}) {
38 0         0 $compiler->set_standard($standard);
39             }
40              
41 2         12 my $node = $compiler->compile($from, $to, %args);
42 2         108 return $planner->add_node($node);
43 2         32 });
44              
45 2   50     55 my $linker_as = delete $opts{linker_as} // 'link';
46             $planner->add_delegate($linker_as, sub {
47 2     2   15 my ($planner, $from, $to, %extra) = @_;
        2      
48 2         10 my %args = (%opts, %extra);
49              
50 2         23 my $linker = $class->make_linker(\%args);
51              
52 2 100 66     14 $args{profiles} = [ delete $args{profile} ] if $args{profile} and not $args{profiles};
53 2   100     4 for my $profile (@{ $args{profiles} // [] }) {
  2         11  
54 1         5 $linker->add_profile($profile, %args);
55             }
56              
57 2 50       9 if (my $library_dirs = $args{library_dirs}) {
58 0         0 $linker->add_library_dirs($library_dirs);
59             }
60 2 50       7 if (my $libraries = $args{libraries}) {
61 0         0 $linker->add_libraries($libraries);
62             }
63 2 50       7 if (my $extra_args = $args{extra_args}) {
64 0         0 $linker->add_argument(ranking => 85, value => [ @{$extra_args} ]);
  0         0  
65             }
66              
67 2         15 my $node = $linker->link($from, $to, %args);
68 2         73 return $planner->add_node($node);
69 2         13 });
70              
71 2         34 for my $name (qw/object_file library_file static_library_file loadable_file executable_file/) {
72 10   33     127 my $format = delete $opts{$name} // croak "No known extension for $name";
73             $planner->add_delegate($name, sub {
74 4     4   890 my ($planner, $file, $dir) = @_;
        4      
        4      
        4      
        4      
        4      
75 4         16 my $filename = sprintf $format, $file;
76 4 50       16 return defined $dir ? catfile($dir, $filename) : $filename;
77 10         44 });
78             }
79             }
80              
81             1;
82              
83             # ABSTRACT: A base class for BuildTools implementations.
84              
85             __END__