File Coverage

blib/lib/Makefile/AST/Rule/Implicit.pm
Criterion Covered Total %
statement 43 57 75.4
branch 10 14 71.4
condition 4 6 66.6
subroutine 9 10 90.0
pod 0 5 0.0
total 66 92 71.7


line stmt bran cond sub pod time code
1             package Makefile::AST::Rule::Implicit;
2              
3 2     2   627 use strict;
  2         3  
  2         80  
4 2     2   9 use warnings;
  2         4  
  2         71  
5              
6             #use Smart::Comments;
7             #use Smart::Comments '####';
8 2     2   11 use base 'Makefile::AST::Rule::Base';
  2         2  
  2         450  
9 2     2   12 use List::Util qw( first );
  2         3  
  2         1475  
10              
11             __PACKAGE__->mk_ro_accessors(qw{
12             targets
13             });
14              
15             sub as_str ($) {
16 0     0 0 0 my $self = shift;
17 0         0 my $order_part = '';
18             ## as_str: order_prereqs: $self->order_prereqs
19 0 0       0 if (@{ $self->order_prereqs }) {
  0         0  
20 0         0 $order_part = " | " . join(" ",@{ $self->order_prereqs });
  0         0  
21             }
22             ### colon: $self->colon
23 0         0 my $str = join(" ", @{ $self->targets }) . " " .
  0         0  
24             $self->colon . " " .
25 0         0 join(" ", @{ $self->normal_prereqs }) . "$order_part ; " .
26 0         0 join("", map { "[$_]" } @{ $self->commands });
  0         0  
27 0         0 $str =~ s/\n+//g;
28 0         0 $str =~ s/ +/ /g;
29 0         0 $str;
30             }
31              
32             # judge if $self is a match anything rule
33             sub match_anything ($) {
34 8     8 0 8 my $self = shift;
35 8     8   22 first { $_ eq '%' } $self->targets;
  8         58  
36             }
37              
38             sub is_terminal ($) {
39 3     3 0 11 $_[0]->colon eq '::';
40             }
41              
42             sub match_target ($$) {
43 14     14 0 14 my ($self, $target) = @_;
44 14         15 for my $pat (@{ $self->targets }) {
  14         27  
45             ### match_target: pattern: $pat
46             ### match_target: target: $target
47 17         87 my $match = Makefile::AST::StemMatch->new(
48             { target => $target, pattern => $pat }
49             );
50 17 100       161 return $match if $match;
51             }
52 3         8 return undef;
53             }
54              
55             # apply the current rule to the given target
56             sub apply ($$$@) {
57 7     7 0 7 my ($self, $ast, $target, $opts) = @_;
58             #### applying implicit rule to target: $target
59 7         6 my $recursive;
60 7 100       11 $recursive = $opts->{recursive} if $opts;
61             #### $recursive
62 7         10 my $match = $self->match_target($target);
63             ## $match
64 7 50       11 return undef if !$match;
65 7         12 my (@other_targets, @normal_prereqs, @order_prereqs);
66 7         7 for (@{ $self->targets }) {
  7         12  
67 14 100       72 next if $_ eq $match->pattern;
68 7         37 push @other_targets, $match->subs_stem($_);
69             }
70 7         9 for (@{ $self->normal_prereqs }) {
  7         13  
71 21         45 push @normal_prereqs, $match->subs_stem($_);
72             }
73 7         7 for (@{ $self->order_prereqs }) {
  7         13  
74 14         36 push @order_prereqs, $match->subs_stem($_);
75             }
76 7         9 for my $prereq (@order_prereqs, @normal_prereqs) {
77             #### Test whether the prereq exists or ought to exist: $prereq
78             #### target exists? : $ast->target_exists($prereq)
79             ## file test: -e 'bar.hpp'
80             #### Target ought to exists? : $ast->target_ought_to_exist($prereq)
81 17 100 66     29 next if $ast->target_exists($prereq) or
82             $ast->target_ought_to_exist($prereq);
83             #### Failed to pass...
84             # XXX mark intermedia files here
85 6 50 66     27 next if $recursive and
86             $ast->apply_implicit_rules($prereq);
87 6         21 return undef;
88             }
89 1         5 return Makefile::AST::Rule->new(
90             {
91             target => $target,
92             colon => $self->colon,
93             stem => $match->stem,
94             normal_prereqs => \@normal_prereqs,
95             order_prereqs => \@order_prereqs,
96             other_targets => \@other_targets,
97             commands => $self->commands,
98             }
99             );
100             }
101              
102             1;
103