X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDX%2FOp%2FFindAll.pm;h=f8770fb9035c78709401f8efa9bddf7d529da8ff;hb=f5a02c91b10ef340dce1e1dacee0a761254f4d80;hp=74caead1669707eaca273186f2048ec39b74cb50;hpb=138613a80580c7ce9808a16591ec7c9c7ea6578e;p=scpubgit%2FDKit.git diff --git a/lib/DX/Op/FindAll.pm b/lib/DX/Op/FindAll.pm index 74caead..f8770fb 100644 --- a/lib/DX/Op/FindAll.pm +++ b/lib/DX/Op/FindAll.pm @@ -7,54 +7,21 @@ use DX::OrderedSet; use DX::Op::Return; use Moo; -with 'DX::Role::Op'; +with 'DX::Role::Op::FindIsh'; has coll_name => (is => 'ro', required => 1); -has var_name => (is => 'ro', required => 1); - -has body => (is => 'ro', required => 1); - -sub run { - my ($self, $state) = @_; - my $values = []; - my $coll = DX::OrderedSet->new(values => $values); - my $collect = DX::Op::FindAllCollect->new( - var_name => $self->var_name, - into => $values - ); - my $do_body = DX::Op::FromCode->new( +sub make_result_handler { + my ($self, $coll) = @_; + my $coll_name = $self->coll_name; + DX::Op::FromCode->new( code => sub { my ($self, $state) = @_; - $state->push_return_then($collect, $self->next); + $state->bind_value($state->scope->{$coll_name} => $coll) + ->then($self->next); }, - next => $self->body - ); - my $var = DX::Var->new(id => "rule:findall") - ->with_stream(DX::ArrayStream->from_array( - $do_body, DX::Op::Return->new - )); - my $invoke = DX::Op::FromCode->new( - code => sub { - my ($self, $state) = @_; - my $op = $state->resolve_value($var); - $state->then($op); - } - ); - my $coll_name = $self->coll_name; - my $ret = DX::Op::SetScope->new( - scope => $state->scope, - next => DX::Op::FromCode->new( - code => sub { - my ($self, $state) = @_; - $state->bind_value($state->scope->{$coll_name} => $coll) - ->then($self->next); - }, - next => $self->next - ) + next => $self->next ); - $state->assign_vars($self->var_name => {}) - ->push_return_then($ret, $invoke)->mark_choice($var); } 1;