File Coverage

blib/lib/ExtUtils/Builder/Compiler.pm
Criterion Covered Total %
statement 59 62 95.1
branch 4 6 66.6
condition 1 2 50.0
subroutine 15 16 93.7
pod 3 10 30.0
total 82 96 85.4


line stmt bran cond sub pod time code
1             package ExtUtils::Builder::Compiler;
2             $ExtUtils::Builder::Compiler::VERSION = '0.035';
3 3     3   1459 use strict;
  3         7  
  3         101  
4 3     3   12 use warnings;
  3         12  
  3         154  
5              
6 3     3   682 use ExtUtils::Builder::Util qw/command require_module/;
  3         11457  
  3         215  
7 3     3   646 use ExtUtils::Builder::Node;
  3         2805  
  3         109  
8              
9 3     3   19 use parent qw/ExtUtils::Builder::ArgumentCollector ExtUtils::Builder::Binary/;
  3         19  
  3         15  
10              
11             sub new {
12 10     10 0 299358 my ($class, %args) = @_;
13 10         40 my $cc = $args{cc};
14 10 100       41 $cc = [ $cc ] if not ref $cc;
15             my $self = bless {
16             cc => $cc,
17             include_dirs => [],
18             defines => [],
19             standard => $args{standard},
20 10         53 }, $class;
21 10         56 $self->_init(%args);
22 10         39 return $self;
23             }
24              
25             sub _init {
26 10     10   28 my ($self, %args) = @_;
27 10         50 $self->ExtUtils::Builder::ArgumentCollector::_init(%args);
28 10         42 $self->ExtUtils::Builder::Binary::_init(%args);
29 10         30 return;
30             }
31              
32             sub compile_flags;
33              
34             sub cc {
35 10     10 0 21 my $self = shift;
36 10         17 return @{ $self->{cc} };
  10         65  
37             }
38              
39             sub add_include_dirs {
40 3     3 1 20 my ($self, $dirs, %opts) = @_;
41 3         14 my $ranking = $self->fix_ranking($self->default_include_ranking, $opts{ranking});
42 3         8 push @{ $self->{include_dirs} }, map { { ranking => $ranking, value => $_ } } @{ $dirs };
  3         8  
  3         15  
  3         6  
43 3         10 return;
44             }
45              
46             sub default_include_ranking {
47 3     3 0 19 return 30;
48             }
49              
50             sub add_defines {
51 4     4 1 33 my ($self, $defines, %opts) = @_;
52 4         16 my $ranking = $self->fix_ranking($self->default_define_ranking, $opts{ranking});
53 4         12 push @{ $self->{defines} }, map { { key => $_, ranking => $ranking, value => $defines->{$_} } } keys %{ $defines };
  4         9  
  4         24  
  4         13  
54 4         51 return;
55             }
56              
57             sub add_profile {
58 1     1 0 4 my ($self, $profile, %args) = @_;
59 1 50       3 if (not ref($profile)) {
60 1         4 $profile =~ s/ \A @ /ExtUtils::Builder::Profile::/xms;
61 1         3 require_module($profile);
62             }
63 1         9 return $profile->process_compiler($self, \%args);
64             }
65              
66             sub default_define_ranking {
67 4     4 0 18 return 40;
68             }
69              
70             sub set_standard {
71 0     0 0 0 my ($self, $version) = @_;
72 0         0 $self->{standard} = $version;
73 0         0 return;
74             }
75              
76             sub collect_arguments {
77 10     10 0 57 my ($self, @args) = @_;
78 10         37 return ($self->SUPER::collect_arguments, $self->compile_flags(@args));
79             }
80              
81             sub compile {
82 10     10 1 63 my ($self, $from, $to, %opts) = @_;
83 10         25 my @actions ;
84 10 50       37 push @actions, $self->_mkdir_for($to) if $opts{mkdir};
85 10         40 my @argv = $self->arguments($from, $to, %opts);
86 10         78 push @actions, command($self->cc, @argv);
87 10   50     5932 my $deps = [ $from, @{ $opts{dependencies} // [] } ];
  10         62  
88 10         48 return ExtUtils::Builder::Node->new(target => $to, dependencies => $deps, actions => \@actions);
89             }
90              
91             1;
92              
93             # ABSTRACT: An interface around different compilers.
94              
95             __END__