my ($var, $array) = @_;
sub {
my ($self, $state) = @_;
- $state->bind_stream_then(
+ $state->then($self->next)->bind_stream(
$state->scope_var($var),
ArrayStream->from_array(@$array),
- $self->next
)
}
}
my $stream = DX::ResultStream->new(for_state => make_state([ 'S' ], $op));
-is($stream->next->{'S'}, $_)
+is($stream->next->value_for('S'), $_)
for qw(jim.example.com joe.example.com bob.example.com);
is($stream->next, undef, 'No more');
)
);
+sub bound_values {
+ map {
+ my $v = $_;
+ +{
+ map +($_ => $v->value_for($_)), $v->var_names,
+ }
+ } @_
+}
+
my $cstream = DX::ResultStream->new(
for_state => make_state([ qw(S P) ], $complex_op)
);
is_deeply(
- [ $cstream->results ],
+ [ bound_values $cstream->results ],
[
{ P => 'csh', S => 'jim.example.com' },
{ P => 'csh', S => 'joe.example.com' },
my $call_op = FromCode->new(
code => sub {
my ($self, $state) = @_;
- my @rst = @{$state->return_stack};
my $save_scope = $state->scope;
my %scope = (S => $save_scope->{S});
my $ret_op = FromCode->new(
code => sub { $_[1]->but(scope => $save_scope, next_op => $_[0]->next) },
next => $self->next,
);
- $state->but(
- scope => \%scope,
- return_stack => [ @rst, $ret_op ],
- next_op => $inner_op
- );
+ $state->but(scope => \%scope)->push_return_then($ret_op, $inner_op);
},
next => FromCode->new(
code => bind_array(P => \@shells),
);
is_deeply(
- [ $callstream->results ],
+ [ bound_values $callstream->results ],
[
{ P => 'csh', S => 'jim.example.com' },
{ P => 'csh', S => 'joe.example.com' },
my $inner_or = FromCode->new(
code => sub { $_[1]->then($var->bound_value) }
);
- $state->but(
- return_stack => [ @{$state->return_stack}, $self->next ],
- next_op => $inner_or
- )->mark_choice($var);
+ $state->push_return_then($self->next, $inner_or)
+ ->mark_choice($var);
};
my $top_or = FromCode->new(
);
is_deeply(
- [ $orstream->results ],
+ [ bound_values $orstream->results ],
[
{
S => "kitty.scsys.co.uk"
);
is_deeply(
- [ $orstream_2->results ],
+ [ bound_values $orstream_2->results ],
[
{
S => "jim.example.com"