File Coverage

blib/lib/App/hopen/Gen/Make/AssetGraphVisitor.pm
Criterion Covered Total %
statement 39 41 95.1
branch 2 4 50.0
condition 1 2 50.0
subroutine 11 12 91.6
pod 2 2 100.0
total 55 61 90.1


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   8 use Data::Hopen qw(hlog getparameters $VERBOSE);
  1         1  
  1         121  
4 1     1   7 use strict; use warnings;
  1     1   3  
  1         21  
  1         5  
  1         2  
  1         26  
5 1     1   5 use Data::Hopen::Base;
  1         2  
  1         9  
6              
7             our $VERSION = '0.000012'; # TRIAL
8              
9 1     1   1380 use parent 'Data::Hopen::Visitor';
  1         2  
  1         5  
10 1     1   63 use Class::Tiny;
  1         2  
  1         6  
11              
12 1     1   38 use App::hopen::BuildSystemGlobals; # for $DestDir
  1         2  
  1         107  
13 1     1   7 use App::hopen::Gen::Make::AssetGraphNode; # for $OUTPUT
  1         2  
  1         21  
14 1     1   4 use Quote::Code;
  1         2  
  1         6  
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 4122 my ($self, %args) = getparameters('self', [qw(goal node_inputs)], @_);
42 1         77 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     705 $args{node_inputs}->find(-name => 'made',
48             -set => '*', -levels => 'local') // {};
49             die 'No input files to goal ' . $args{goal}->name
50 1 50       204 unless scalar keys %$hrInputs;
51              
52 1         4 my $lrInputs = $hrInputs->{(keys %$hrInputs)[0]};
53 1     0   9 hlog { __PACKAGE__, 'found inputs to goal', $args{goal}->name, Dumper($lrInputs) } 2;
  0         0  
54              
55 1         10 my @paths = map { $_->target->path_wrt($DestDir) } @$lrInputs;
  1         5  
56 1 50       316 print $fh qc'\n# === Makefile goal {$args{goal}->name}\n' if $VERBOSE;
  0         0  
57 1         3 print $fh qc'{$args{goal}->name}: ';
  1         17  
58 1         17 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: #