Skip to content

Commit

Permalink
Remove phase from Data::Hopen (#5)
Browse files Browse the repository at this point in the history
No longer treat -phase specially when running DAGs.
  • Loading branch information
cxw42 committed Dec 27, 2020
1 parent ff78113 commit 458210b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Revision history for Data-Hopen

0.000019 2020-12-26
- No longer treat -phase specially when running DAGs.

0.000018 2020-05-14
- Fix dependencies (again) (cpantesters++)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

`Data::Hopen` is a dataflow library that runs actions you specify, moves data
between those actions, and permits transforming data as the data moves. It is
the underlying engine of the [App::hopen](https://metacpan.org/pod/App::hopen) cross-platform software build
the underlying engine of the [App::hopen](https://metacpan.org/pod/App%3A%3Ahopen) cross-platform software build
generator, but can be used for any dataflow task that can be represented as a
directed acyclic graph (DAG).

Expand Down
5 changes: 2 additions & 3 deletions lib/Data/Hopen/G/DAG.pm
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ the order those predecessors were added to the graph.

# The implementation of run(). $self->scope has already been linked to the context.
sub _run {
my ($self, %args) = getparameters('self', [qw(; phase visitor)], @_);
my ($self, %args) = getparameters('self', [qw(; visitor)], @_);
my $retval = {};

# --- Get the initialization ops ---
Expand Down Expand Up @@ -269,7 +269,6 @@ sub _run {

$hrLinkOutputs = $link->run(
-context=>$scLinkInputs,
forward_opts(\%args, {'-'=>1}, 'phase')
# visitor not passed to links.
);
$scLinkInputs = make_link_inputs($hrLinkOutputs);
Expand All @@ -281,7 +280,7 @@ sub _run {
} #foreach predecessor node

my $step_output = $node->run(-context=>$node_inputs,
forward_opts(\%args, {'-'=>1}, 'phase', 'visitor')
forward_opts(\%args, {'-'=>1}, 'visitor')
);
$node->outputs($step_output);

Expand Down
4 changes: 2 additions & 2 deletions lib/Data/Hopen/G/Goal.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ Passes through the inputs if L</should_output> is set.
# }}}1

sub _run {
my ($self, %args) = getparameters('self', [qw(; phase visitor)], @_);
my ($self, %args) = getparameters('self', [qw(; visitor)], @_);
hlog { Goal => $self->name, ($self->should_output ? 'with' : 'without'),
'outputs' };

return {} unless $self->should_output;

return $self->passthrough(-nocontext=>1, -levels => 'local',
forward_opts(\%args, {'-'=>1}, qw[phase visitor]));
forward_opts(\%args, {'-'=>1}, qw[visitor]));
} #_run()

=head2 BUILD
Expand Down
2 changes: 1 addition & 1 deletion lib/Data/Hopen/G/Link.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ By default, the output is a copy of the inputs
=cut

sub _run {
my ($self, %args) = getparameters('self', [qw(; phase visitor)], @_);
my ($self, %args) = getparameters('self', [qw(; visitor)], @_);
return $self->passthrough(-nocontext => 1);
} #run()

Expand Down
14 changes: 5 additions & 9 deletions lib/Data/Hopen/G/Runnable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ A L<Data::Hopen::Scope> or subclass including the inputs the caller wants to
pass to the Runnable. The L</scope> of the Runnable itself may override
values in the C<context>.
=item -phase
If given, the phase that is currently under way in a build-system run.
=item -visitor
If given, an instance that supports C<visit_goal()> and C<visit_node()> calls.
Expand All @@ -106,7 +102,7 @@ scope.
=cut

sub run {
my ($self, %args) = getparameters('self', [qw(; context phase visitor nocontext)], @_);
my ($self, %args) = getparameters('self', [qw(; context visitor nocontext)], @_);
my $context_scope = $args{context}; # which may be undef - that's OK
croak "Can't combine -context and -nocontext" if $args{context} && $args{nocontext};

Expand All @@ -115,7 +111,7 @@ sub run {

hlog { '->', ref($self), $self->name, 'input', Dumper($self->scope->as_hashref) } 3;

my $retval = $self->_run(forward_opts(\%args, {'-'=>1}, qw[phase visitor]));
my $retval = $self->_run(forward_opts(\%args, {'-'=>1}, qw[visitor]));

die "$self\->_run() did not return a hashref" unless ref $retval eq 'HASH';
# Prevent errors about `non-hashref 1` or `invalid key`.
Expand All @@ -131,13 +127,13 @@ The internal method that implements L</run>. Must be implemented by
subclasses. When C<_run> is called, C<< $self->scope >> has been hooked
to the context scope, if any.
Parameters are C<-phase> and C<-visitor>, and are always passed by name
(C<< -phase=>$p, -visitor=>$v >>). C<_run> is always called in scalar context,
The only parameter is C<-visitor>, which is always passed by name
(C<< -visitor=>$v >>). C<_run> is always called in scalar context,
and B<must> return a new hashref.
I recommend starting your C<_run> function with:
my ($self, %args) = getparameters('self', [qw(; phase visitor)], @_);
my ($self, %args) = getparameters('self', [qw(; visitor)], @_);
and working from there.
Expand Down
6 changes: 3 additions & 3 deletions t/125-dag-links.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sub make_dag { # See t/121-dag-single-goal.t for the explanation of this
use Data::Hopen;
use parent 'Data::Hopen::G::Link';
sub _run {
my ($self, %args) = getparameters('self', [qw(; phase visitor)], @_);
my ($self, %args) = getparameters('self', [qw(; visitor)], @_);
return { xyzzy => 'plugh' };
}
}
Expand All @@ -46,7 +46,7 @@ sub make_dag { # See t/121-dag-single-goal.t for the explanation of this
use Class::Tiny {to_add => sub { +{ xyzzy => 'plugh' } } };

sub _run {
my ($self, %args) = getparameters('self', [qw(; phase visitor)], @_);
my ($self, %args) = getparameters('self', [qw(; visitor)], @_);
my $inputs = $self->scope->as_hashref(-levels => 3);
return +{ %$inputs, %{$self->to_add} };
}
Expand All @@ -57,7 +57,7 @@ sub make_dag { # See t/121-dag-single-goal.t for the explanation of this
use Data::Hopen;
use parent 'Data::Hopen::G::Link';
sub _run {
my ($self, %args) = getparameters('self', [qw(; phase visitor)], @_);
my ($self, %args) = getparameters('self', [qw(; visitor)], @_);
my $inputs = $self->scope->as_hashref;
my $multiplier = $inputs->{multiplier} // 2;
$inputs->{foo} *= $multiplier if exists $inputs->{foo};
Expand Down

0 comments on commit 458210b

Please sign in to comment.