File Coverage

blib/lib/App/hopen/Gen/Ninja/AssetGraphVisitor.pm
Criterion Covered Total %
statement 41 43 95.3
branch 2 4 50.0
condition 1 2 50.0
subroutine 11 12 91.6
pod 2 2 100.0
total 57 63 90.4


line stmt bran cond sub pod time code
1             # App::hopen::Gen::Ninja::AssetGraphVisitor - visitor to write goals
2             package App::hopen::Gen::Ninja::AssetGraphVisitor;
3 1     1   8 use Data::Hopen qw(hlog getparameters $VERBOSE);
  1         2  
  1         98  
4 1     1   6 use strict; use warnings;
  1     1   2  
  1         19  
  1         4  
  1         3  
  1         24  
5 1     1   5 use Data::Hopen::Base;
  1         2  
  1         6  
6              
7             our $VERSION = '0.000012'; # TRIAL
8              
9 1     1   1398 use parent 'Data::Hopen::Visitor';
  1         2  
  1         5  
10 1     1   64 use Class::Tiny;
  1         3  
  1         7  
11              
12 1     1   35 use App::hopen::BuildSystemGlobals; # for $DestDir
  1         2  
  1         108  
13 1     1   8 use App::hopen::Gen::Ninja::AssetGraphNode; # for OUTPUT
  1         4  
  1         22  
14 1     1   4 use Quote::Code;
  1         3  
  1         5  
15              
16             # Docs {{{1
17              
18             =head1 NAME
19              
20             App::hopen::Gen::Ninja::AssetGraphVisitor - visitor to write goals
21              
22             =head1 SYNOPSIS
23              
24             This is the visitor used when L<App::hopen::Gen::Ninja> 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 Ninja file being built.
36             This happens while the asset graph is being run.
37              
38             =cut
39              
40             sub visit_goal {
41 1     1 1 4168 my ($self, %args) = getparameters('self', [qw(goal node_inputs)], @_);
42 1         78 my $fh = $args{node_inputs}->find(App::hopen::Gen::Ninja::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     700 $args{node_inputs}->find(-name => 'made',
48             -set => '*', -levels => 'local') // {};
49             die 'No input files to goal ' . $args{goal}->name
50 1 50       2057 unless scalar keys %$hrInputs;
51              
52 1         4 my $lrInputs = $hrInputs->{(keys %$hrInputs)[0]};
53 1     0   10 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         16  
56 1 50       363 say $fh qc'\n# === Ninja file goal {$args{goal}->name}' if $VERBOSE;
  0         0  
57 1         3 say $fh qc'build {$args{goal}->name}: phony {join " ", @paths}';
  1         8  
  1         14  
58 1         10 say $fh qc'default {$args{goal}->name}';
  1         4  
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: #