File Coverage

blib/lib/Make/Target.pm
Criterion Covered Total %
statement 55 55 100.0
branch 9 12 75.0
condition 8 10 80.0
subroutine 14 14 100.0
pod 0 11 0.0
total 86 102 84.3


line stmt bran cond sub pod time code
1             package Make::Target;
2              
3 1     1   6 use strict;
  1         2  
  1         28  
4 1     1   5 use warnings;
  1         2  
  1         33  
5             ## no critic (ValuesAndExpressions::ProhibitConstantPragma)
6 1     1   6 use constant DEBUG => $ENV{MAKE_DEBUG};
  1         1  
  1         832  
7             ## use critic
8              
9             our $VERSION = '2.011';
10              
11             # Intermediate 'target' package
12             # There is an instance of this for each 'target' that apears on
13             # the left hand side of a rule i.e. for each thing that can be made.
14             sub new {
15 131     131 0 245 my ( $class, $name, $info ) = @_;
16 131         984 return bless {
17             NAME => $name, # name of thing
18             MAKEFILE => $info, # Makefile context
19             RULES => [],
20             RULE_TYPE => undef, # undef, :, ::
21             HAS_RECIPE => undef, # undef, boolean
22             Pass => 0, # Used to determine if 'done' this sweep
23             }, $class;
24             }
25              
26             sub date {
27 12     12 0 19 my $self = shift;
28 12         27 my $info = $self->Info;
29 12         23 return $info->date( $self->Name );
30             }
31              
32             sub phony {
33 157     157 0 216 my $self = shift;
34 157         265 return $self->Info->phony( $self->Name );
35             }
36              
37             sub has_recipe {
38 151     151 0 242 my ($self) = @_;
39 151 100       366 return $self->{HAS_RECIPE} if defined $self->{HAS_RECIPE};
40             ## no critic (BuiltinFunctions::RequireBlockGrep)
41 106         169 return $self->{HAS_RECIPE} = grep @{ $_->recipe }, @{ $self->{RULES} };
  91         215  
  106         232  
42             ## use critic
43             }
44              
45             sub rules {
46 156     156 0 247 my ($self) = @_;
47 156 100 100     285 if ( !$self->phony && !$self->has_recipe ) {
48 47   100     89 my $rule = $self->Info->patrule( $self->Name, $self->{RULE_TYPE} || ':' );
49 47         87 DEBUG and print STDERR "Implicit rule (", $self->Name, "): @{ $rule ? $rule->prereqs : ['none'] }\n";
50 47 100       109 $self->add_rule($rule) if $rule;
51             }
52 156         491 return $self->{RULES};
53             }
54              
55             sub add_rule {
56 125     125 0 221 my ( $self, $rule ) = @_;
57 125         255 my $new_kind = $rule->kind;
58 125   66     490 my $kind = $self->{RULE_TYPE} ||= $new_kind;
59 125 50       257 die "Target '$self->{NAME}' had '$kind' but tried to add '$new_kind'"
60             if $kind ne $new_kind;
61 125   50     444 $self->{HAS_RECIPE} ||= undef; # reset if was no or unknown
62 125         168 return push @{ shift->{RULES} }, $rule;
  125         527  
63             }
64              
65             sub Name {
66 235     235 0 765 return shift->{NAME};
67             }
68              
69             sub Base {
70 1     1 0 4 my $name = shift->{NAME};
71 1         21 $name =~ s/\.[^.]+$//;
72 1         8 return $name;
73             }
74              
75             sub Info {
76 290     290 0 529 return shift->{MAKEFILE};
77             }
78              
79             sub done {
80 20     20 0 31 my $self = shift;
81 20         39 my $pass = $self->Info->pass;
82 20 50       51 return 1 if ( $self->{Pass} == $pass );
83 20         32 $self->{Pass} = $pass;
84 20         71 return 0;
85             }
86              
87             # as part of "out of date" processing, if any child is remade, I need too
88             sub recurse {
89 20     20 0 42 my ( $self, $method ) = @_;
90 20 50       43 return if $self->done;
91 20         44 my $info = $self->Info;
92 20         31 my @results;
93 20         23 DEBUG and print STDERR "Build " . $self->Name, "\n";
94 20         24 foreach my $rule ( @{ $self->rules } ) {
  20         35  
95             ## no critic (BuiltinFunctions::RequireBlockMap)
96 12         24 push @results, map $info->target($_)->recurse($method), @{ $rule->prereqs };
  12         29  
97             ## use critic
98 12         92 push @results, $rule->$method($self);
99             }
100 20         96 return @results;
101             }
102              
103             1;