File Coverage

blib/lib/App/hopen/Gen/Make/AssetGraphVisitor.pm
Criterion Covered Total %
statement 36 38 94.7
branch 2 4 50.0
condition 1 2 50.0
subroutine 10 11 90.9
pod 2 2 100.0
total 51 57 89.4


line stmt bran cond sub pod time code
1             # App::hopen::Gen::Make::AssetGraphVisitor - visitor to write goals
2             package App::hopen::Gen::Make::AssetGraphVisitor;
3 1     1   10 use Data::Hopen qw(hlog getparameters $VERBOSE);
  1         5  
  1         210  
4 1     1   10 use strict;
  1         2  
  1         25  
5 1     1   6 use Data::Hopen::Base;
  1         2  
  1         7  
6              
7             our $VERSION = '0.000011';
8              
9 1     1   1485 use parent 'Data::Hopen::Visitor';
  1         3  
  1         7  
10 1     1   65 use Class::Tiny;
  1         2  
  1         11  
11              
12 1     1   41 use App::hopen::BuildSystemGlobals; # for $DestDir
  1         2  
  1         132  
13 1     1   9 use App::hopen::Gen::Make::AssetGraphNode; # for $OUTPUT
  1         2  
  1         36  
14 1     1   7 use Quote::Code;
  1         2  
  1         14  
15              
16             # Docs {{{1
17              
18             =head1 NAME
19              
20             App::hopen::Gen::Make::AssetGraphVisitor - visitor to write goals
21              
22             =head1 SYNOPSIS
23              
24             This is the visitor used when L<App::hopen::Gen::Make> traverses the
25             asset graph. Its purpose is to tie the inputs to each goal into that goal.
26              
27             =head1 FUNCTIONS
28              
29             =cut
30              
31             # }}}1
32              
33             =head2 visit_goal
34              
35             Write a goal entry to the Makefile being built.
36             This happens while the asset graph is being run.
37              
38             =cut
39              
40             sub visit_goal {
41 1     1 1 4121 my ($self, %args) = getparameters('self', [qw(goal node_inputs)], @_);
42 1         82 my $fh = $args{node_inputs}->find(App::hopen::Gen::Make::AssetGraphNode::OUTPUT);
43              
44             # Pull the inputs. TODO refactor out the code in common with
45             # AhG::Cmd::input_assets().
46             my $hrInputs =
47 1   50     736 $args{node_inputs}->find(-name => 'made',
48             -set => '*', -levels => 'local') // {};
49             die 'No input files to goal ' . $args{goal}->name
50 1 50       208 unless scalar keys %$hrInputs;
51              
52 1         5 my $lrInputs = $hrInputs->{(keys %$hrInputs)[0]};
53 1     0   8 hlog { __PACKAGE__, 'found inputs to goal', $args{goal}->name, Dumper($lrInputs) } 2;
  0         0  
54              
55 1         11 my @paths = map { $_->target->path_wrt($DestDir) } @$lrInputs;
  1         5  
56 1 50       321 print $fh qc'\n# === Makefile goal {$args{goal}->name}\n' if $VERBOSE;
  0         0  
57 1         4 print $fh qc'{$args{goal}->name}: ';
  1         7  
58 1         16 say $fh join ' ', @paths;
59             } #visit_goal()
60              
61             =head2 visit_node
62              
63             No-op.
64              
65             =cut
66              
67       3 1   sub visit_node { }
68              
69             1;
70             __END__
71             # vi: set fdm=marker: #