File Coverage

blib/lib/Build/Hopen/G/Runnable.pm
Criterion Covered Total %
statement 32 37 86.4
branch n/a
condition n/a
subroutine 8 9 88.8
pod 2 2 100.0
total 42 48 87.5


line stmt bran cond sub pod time code
1             # Build::Hopen::G::Runnable - parent class for anything runnable in a hopen graph
2             package Build::Hopen::G::Runnable;
3 7     7   2702 use Build::Hopen::Base;
  7         13  
  7         34  
4              
5             our $VERSION = '0.000006'; # TRIAL
6              
7 7     7   3251 use Build::Hopen::Scope::Hash;
  7         17  
  7         243  
8 7     7   74 use Build::Hopen::Util::NameSet;
  7         11  
  7         134  
9 7     7   31 use Build::Hopen::Arrrgs;
  7         10  
  7         230  
10 7     7   2846 use Hash::Merge;
  7         22727  
  7         303  
11              
12             # Docs {{{1
13              
14             =head1 NAME
15              
16             Build::Hopen::G::Runnable - parent class for runnable things in a hopen graph
17              
18             =head1 SYNOPSIS
19              
20             Anything with L inherits from this. TODO should this be a role?
21              
22             =head1 ATTRIBUTES
23              
24             =head2 need
25              
26             Inputs this Runnable requires.
27             A L, with the restriction that C may not
28             contain regexes. ("Sorry, I can't run unless you give me every variable
29             in the world that starts with Q." I don't think so!)
30              
31             =head2 scope
32              
33             If defined, a L that will have the final say on the
34             data used by L. This is the basis of the fine-grained override
35             mechanism in hopen.
36              
37             =head2 want
38              
39             Inputs this Runnable accepts but does not require.
40             A L, which may include regexes.
41              
42             =cut
43              
44             # }}}1
45              
46 7     7   44 use parent 'Build::Hopen::G::Entity';
  7         11  
  7         39  
47             use Class::Tiny {
48             # NOTE: want and need are not currently used.
49 0         0 want => sub { Build::Hopen::Util::NameSet->new },
50 4         48 need => sub { Build::Hopen::Util::NameSet->new },
51              
52 6         55 scope => sub { Build::Hopen::Scope::Hash->new },
53 7     7   576 };
  7         11  
  7         52  
54              
55             =head1 FUNCTIONS
56              
57             =head2 run
58              
59             Run the operation, whatever that means. B return a new hashref.
60             Must be implemented by subclasses. Usage:
61              
62             my $hrOutputs = $op->run([options])
63              
64             Options are:
65              
66             =over
67              
68             =item -scope
69              
70             A L or subclass including the inputs the caller wants to
71             pass to the Runnable. The Runnable itself should use its own L,
72             usually by setting C<< $self->scope->outer($outer_scope) >> within its
73             C call.
74              
75             =item -phase
76              
77             If given, the phase that is currently under way in a build-system run.
78              
79             =item -generator
80              
81             If given, the L instance in use for the current
82             build-system run.
83              
84             =back
85              
86             See the source for this function, which contains as an example of setting the
87             scope.
88              
89             =cut
90              
91             sub run {
92 0     0 1 0 my ($self, %args) = parameters('self', [qw(; scope phase generator)], @_);
93 0         0 my $outer_scope = $args{scope}; # which may be undef - that's OK
94              
95             # Link the outer scope to our scope
96 0         0 my $saver = $self->scope->outerize($outer_scope);
97             ... # Subclasses have to do the work. TODO provide _run_inner for
98             # use by subclasses?
99 0         0 } #run()
100              
101             =head2 passthrough
102              
103             Returns a new hashref of this Runnable's local values, as defined
104             by L. Usage:
105              
106             my $hashref = $runnable->passthrough([-scope => $outer_scope])
107              
108             =cut
109              
110             # TODO RESUME HERE - update this to handle $scope->inputs() correctly.
111             # Maybe just pass the inputs(), not anything else?
112             sub passthrough {
113 6     6 1 23 my ($self, %args) = parameters('self', [qw(; scope)], @_);
114 6         16 my $outer_scope = $args{scope}; # which may be undef - that's OK
115              
116             # Link the outer scope to our scope
117 6         126 my $saver = $self->scope->outerize($outer_scope);
118              
119 6         80 my $names = $self->scope->names('local');
120              
121 6         13 my $retval = {};
122 6         17 foreach my $input (@{$names}) {
  6         17  
123 8         153 $retval->{$input} = $self->scope->find($input, -levels=>'local');
124             }
125 6         38 return $retval;
126             } #passthrough()
127              
128             1;
129             __END__