From: Matt S Trout Date: Mon, 20 Jan 2014 12:35:51 +0000 (+0000) Subject: move return stack code back to test X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=54817920c3d58b651b01cafa669335f61d9906e9;p=scpubgit%2FDKit.git move return stack code back to test --- diff --git a/lib/DX/State.pm b/lib/DX/State.pm index 66287dd..4815ab2 100644 --- a/lib/DX/State.pm +++ b/lib/DX/State.pm @@ -54,28 +54,12 @@ sub then { $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; diff --git a/t/basic.t b/t/basic.t index d3c636a..2175524 100644 --- a/t/basic.t +++ b/t/basic.t @@ -48,12 +48,18 @@ sub test_values { } } -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) = @_; @@ -105,6 +111,15 @@ is_deeply( '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) = @_; @@ -118,7 +133,7 @@ my $call_op = FromCode->new( $state->new(%$state, scope => \%scope, return_stack => [ @rst, $ret_op ], - next_op => $op + next_op => $inner_op ); }, next => FromCode->new(