File Coverage

blib/lib/App/hopen/Gen/Make/AssetGraphNode.pm
Criterion Covered Total %
statement 54 60 90.0
branch 7 8 87.5
condition 2 6 33.3
subroutine 12 12 100.0
pod n/a
total 75 86 87.2


line stmt bran cond sub pod time code
1             # App::hopen::Gen::Make::AssetGraphNode - AssetOp for Gen::Make
2             package App::hopen::Gen::Make::AssetGraphNode;
3 1     1   9 use Data::Hopen qw(getparameters *VERBOSE);
  1         2  
  1         91  
4 1     1   38 use strict; use warnings;
  1     1   2  
  1         21  
  1         6  
  1         2  
  1         53  
5 1     1   5 use Data::Hopen::Base;
  1         2  
  1         10  
6              
7             our $VERSION = '0.000013'; # TRIAL
8              
9 1     1   1417 use parent 'App::hopen::G::AssetOp';
  1         2  
  1         10  
10 1     1   46 use Class::Tiny;
  1         2  
  1         5  
11              
12 1     1   34 use App::hopen::BuildSystemGlobals; # for $DestDir
  1         2  
  1         115  
13 1     1   6 use Quote::Code;
  1         2  
  1         5  
14 1     1   610 use String::Print;
  1         73692  
  1         7  
15              
16             # Docs {{{1
17              
18             =head1 NAME
19              
20             App::hopen::Gen::Make::AssetGraphNode - AssetOp for Gen::Make
21              
22             =head1 SYNOPSIS
23              
24             TODO
25              
26             =head1 FUNCTIONS
27              
28             =cut
29              
30             # }}}1
31              
32 1     1   181 use vars::i '&OUTPUT' => sub { '__R_Makefile' };
  1     5   2  
  1         15  
  5         43  
33              
34             =head2 _run
35              
36             Generate a piece of a Makefile and write it to the filehandle in
37             C<__R_Makefile>.
38              
39             If the `how` of a node is defined but falsy, it's a goal.
40             If `how` is defined and truthy, it's a file.
41              
42             =cut
43              
44             sub _run {
45 4     4   1125 my ($self, %args) = getparameters('self', [qw(; phase visitor)], @_);
46 4         270 my $fh = $self->scope->find(OUTPUT);
47             # TODO deal with multiple inputs being merged in DAG::_run()
48              
49 4         4094 my @inputs = $self->input_assets;
50 4         26 my $output = $self->asset->target;
51 4 100       9 $output = $output->path_wrt($DestDir) if eval { $output->DOES('App::hopen::Util::BasedPath') };
  4         48  
52             # TODO refactor this processing into a utility module/function
53              
54             # Debugging output
55 4 50       1075 if($VERBOSE) {
56 0         0 say $fh qc'\n# Makefile piece from node {$self->name}';
  0         0  
57 0   0     0 say $fh qc' # {$self->how//"<nothing to be done>"}';
  0         0  
58 0         0 say $fh qc' # Depends on {$_->target}' foreach @inputs;
  0         0  
59             }
60              
61 4 100       124 if(defined $self->how) {
62 3         25 my @paths = map { $_->target->path_wrt($DestDir) } @inputs;
  3         11  
63 3         1467 my $recipe = $self->how;
64             # TODO refactor this processing into a utility module/function
65 3   50     26 $recipe =~ s<#first\b><$paths[0] // ''>ge; # first input
  1         4  
66 3         52 $recipe =~ s<#all\b><join(' ', @paths)>ge; # all inputs
  1         5  
67 3   50     28 $recipe =~ s<#out\b><$output // ''>ge;
  2         6  
68              
69             # Emit the entry. If the recipe is defined but falsy,
70             # this is a goal, so it gets a .PHONY.
71 3         10 print $fh qc_to <<"EOT"
  3         18  
72 3 100       24 #{$output}: #{join(" ", @paths)}
  3         64  
73             #{$recipe ? "\t$recipe" : ".PHONY: $output"}
74              
75             EOT
76              
77             }
78              
79 4         22 $self->make($self->asset);
80 4         18 return {};
81             } #_run()
82              
83             1;
84             __END__
85             # vi: set fdm=marker: #