| 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 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 101 |  | 
| 4 | 1 |  |  | 1 |  | 8 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 23 |  | 
| 5 | 1 |  |  | 1 |  | 6 | use Data::Hopen::Base; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '0.000011'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 1456 | use parent 'Data::Hopen::Visitor'; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 10 | 1 |  |  | 1 |  | 68 | use Class::Tiny; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 1 |  |  | 1 |  | 52 | use App::hopen::BuildSystemGlobals;     # for $DestDir | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 109 |  | 
| 13 | 1 |  |  | 1 |  | 7 | use App::hopen::Gen::Ninja::AssetGraphNode;     # for OUTPUT | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 32 |  | 
| 14 | 1 |  |  | 1 |  | 7 | use Quote::Code; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 9 |  | 
| 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 | 4192 | my ($self, %args) = getparameters('self', [qw(goal node_inputs)], @_); | 
| 42 | 1 |  |  |  |  | 79 | 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 |  |  | 704 | $args{node_inputs}->find(-name => 'made', | 
| 48 |  |  |  |  |  |  | -set => '*', -levels => 'local') // {}; | 
| 49 |  |  |  |  |  |  | die 'No input files to goal ' . $args{goal}->name | 
| 50 | 1 | 50 |  |  |  | 206 | 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 |  |  |  |  | 9 | my @paths = map { $_->target->path_wrt($DestDir) } @$lrInputs; | 
|  | 1 |  |  |  |  | 5 |  | 
| 56 | 1 | 50 |  |  |  | 365 | say $fh qc'\n# === Ninja file goal {$args{goal}->name}' if $VERBOSE; | 
|  | 0 |  |  |  |  | 0 |  | 
| 57 | 1 |  |  |  |  | 4 | say $fh qc'build {$args{goal}->name}: phony {join " ", @paths}'; | 
|  | 1 |  |  |  |  | 10 |  | 
|  | 1 |  |  |  |  | 14 |  | 
| 58 | 1 |  |  |  |  | 10 | say $fh qc'default {$args{goal}->name}'; | 
|  | 1 |  |  |  |  | 5 |  | 
| 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: # |