$self->new(%$self, next_op => $then);
}
-sub select_next_op {
- my ($self) = @_;
- return $self->next_op || do {
- if (my @stack = @{$self->return_stack}) {
- my $top = pop @stack;
- DX::Op::FromCode->new(
- code => sub {
- $_[1]->new(%{$_[1]}, return_stack => \@stack, next_op => $top)
- }
- );
- } else {
- undef;
- }
- };
-}
-
sub run {
my ($state) = @_;
with_return {
my ($return) = @_;
local our $No_Options_Handler = $return;
- while (my $op = $state->select_next_op) {
+ while (my $op = $state->next_op) {
$state = $op->run($state);
}
return $state;
}
}
-my $op = FromCode->new(
- code => bind_array(S => \@servers),
- next => FromCode->new(
- code => test_values([ 'S' ], sub { $_[0] =~ /\.example\.com$/ })
- )
-);
+sub make_op {
+ my ($inner) = @_;
+ FromCode->new(
+ code => bind_array(S => \@servers),
+ next => FromCode->new(
+ code => test_values([ 'S' ], sub { $_[0] =~ /\.example\.com$/ }),
+ next => $inner,
+ )
+ );
+}
+
+my $op = make_op;
sub make_state {
my ($vars, $op) = @_;
'Complex stream'
);
+my $inner_op = make_op(FromCode->new(
+ code => sub {
+ my ($self, $state) = @_;
+ my @stack = @{$state->return_stack};
+ my $top = pop @stack;
+ $state->new(%$state, return_stack => \@stack, next_op => $top);
+ }
+));
+
my $call_op = FromCode->new(
code => sub {
my ($self, $state) = @_;
$state->new(%$state,
scope => \%scope,
return_stack => [ @rst, $ret_op ],
- next_op => $op
+ next_op => $inner_op
);
},
next => FromCode->new(