File Coverage

blib/lib/Data/Hopen/G/Goal.pm
Criterion Covered Total %
statement 25 25 100.0
branch 6 6 100.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 41 41 100.0


line stmt bran cond sub pod time code
1             # Data::Hopen::G::Goal - A named build goal
2             package Data::Hopen::G::Goal;
3 9     9   23607 use strict;
  9         32  
  9         265  
4 9     9   49 use Data::Hopen::Base;
  9         20  
  9         59  
5              
6             our $VERSION = '0.000018';
7              
8 9     9   2102 use parent 'Data::Hopen::G::Op';
  9         23  
  9         68  
9             use Class::Tiny {
10 9         100 should_output => true, # if true, forward the goal's inputs as
11             # its outputs.
12 9     9   606 };
  9         18  
13              
14 9     9   2269 use Data::Hopen;
  9         22  
  9         592  
15 9     9   59 use Data::Hopen::Util::Data qw(forward_opts);
  9         16  
  9         2334  
16              
17             # Docs {{{1
18              
19             =head1 NAME
20              
21             Data::Hopen::G::Goal - a named goal in a hopen build
22              
23             =head1 SYNOPSIS
24              
25             A C is a named build target, e.g., C or C. The name C
26             is reserved for the root goal. Goals usually appear at the end of the build
27             graph, but this is not required --- Goal nodes can appear anywhere in the
28             graph.
29              
30             =head1 MEMBERS
31              
32             =head2 should_output
33              
34             Boolean, default true. If false, the goal's outputs are always C<{}> (empty).
35             If true, the goal's inputs are passed through as outputs.
36              
37             =head1 FUNCTIONS
38              
39             =head2 run
40              
41             Passes through the inputs if L is set.
42              
43             =cut
44              
45             # }}}1
46              
47             sub _run {
48 27     27   158 my ($self, %args) = getparameters('self', [qw(; phase visitor)], @_);
49 20 100   20   79 hlog { Goal => $self->name, ($self->should_output ? 'with' : 'without'),
50 27         1300 'outputs' };
51              
52 27 100       733 return {} unless $self->should_output;
53              
54 25         363 return $self->passthrough(-nocontext=>1, -levels => 'local',
55             forward_opts(\%args, {'-'=>1}, qw[phase visitor]));
56             } #_run()
57              
58             =head2 BUILD
59              
60             Enforce the requirement for a user-specified name.
61              
62             =cut
63              
64             sub BUILD {
65 17     17 1 2529 my ($self, $args) = @_;
66 17 100       365 croak 'Goals must have names' unless $args->{name};
67             } #BUILD()
68              
69             1;
70             __END__