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         32  
5             ## no critic (ValuesAndExpressions::ProhibitConstantPragma)
6 1     1   4 use constant DEBUG => $ENV{MAKE_DEBUG};
  1         2  
  1         840  
7             ## use critic
8              
9             our $VERSION = '2.010';
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 229 my ( $class, $name, $info ) = @_;
16 131         1045 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 17 my $self = shift;
28 12         19 my $info = $self->Info;
29 12         33 return $info->date( $self->Name );
30             }
31              
32             sub phony {
33 157     157 0 232 my $self = shift;
34 157         271 return $self->Info->phony( $self->Name );
35             }
36              
37             sub has_recipe {
38 151     151 0 255 my ($self) = @_;
39 151 100       357 return $self->{HAS_RECIPE} if defined $self->{HAS_RECIPE};
40             ## no critic (BuiltinFunctions::RequireBlockGrep)
41 106         134 return $self->{HAS_RECIPE} = grep @{ $_->recipe }, @{ $self->{RULES} };
  91         184  
  106         249  
42             ## use critic
43             }
44              
45             sub rules {
46 156     156 0 270 my ($self) = @_;
47 156 100 100     292 if ( !$self->phony && !$self->has_recipe ) {
48 47   100     86 my $rule = $self->Info->patrule( $self->Name, $self->{RULE_TYPE} || ':' );
49 47         83 DEBUG and print STDERR "Implicit rule (", $self->Name, "): @{ $rule ? $rule->prereqs : ['none'] }\n";
50 47 100       131 $self->add_rule($rule) if $rule;
51             }
52 156         532 return $self->{RULES};
53             }
54              
55             sub add_rule {
56 125     125 0 225 my ( $self, $rule ) = @_;
57 125         256 my $new_kind = $rule->kind;
58 125   66     426 my $kind = $self->{RULE_TYPE} ||= $new_kind;
59 125 50       240 die "Target '$self->{NAME}' had '$kind' but tried to add '$new_kind'"
60             if $kind ne $new_kind;
61 125   50     407 $self->{HAS_RECIPE} ||= undef; # reset if was no or unknown
62 125         154 return push @{ shift->{RULES} }, $rule;
  125         501  
63             }
64              
65             sub Name {
66 235     235 0 732 return shift->{NAME};
67             }
68              
69             sub Base {
70 1     1 0 3 my $name = shift->{NAME};
71 1         15 $name =~ s/\.[^.]+$//;
72 1         9 return $name;
73             }
74              
75             sub Info {
76 290     290 0 599 return shift->{MAKEFILE};
77             }
78              
79             sub done {
80 20     20 0 31 my $self = shift;
81 20         37 my $pass = $self->Info->pass;
82 20 50       69 return 1 if ( $self->{Pass} == $pass );
83 20         32 $self->{Pass} = $pass;
84 20         39 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 37 my ( $self, $method ) = @_;
90 20 50       44 return if $self->done;
91 20         39 my $info = $self->Info;
92 20         29 my @results;
93 20         23 DEBUG and print STDERR "Build " . $self->Name, "\n";
94 20         27 foreach my $rule ( @{ $self->rules } ) {
  20         46  
95             ## no critic (BuiltinFunctions::RequireBlockMap)
96 12         23 push @results, map $info->target($_)->recurse($method), @{ $rule->prereqs };
  12         31  
97             ## use critic
98 12         46 push @results, $rule->$method($self);
99             }
100 20         82 return @results;
101             }
102              
103             1;