factor out arg handling
[scpubgit/DKit.git] / lib / DX / Op / ApplyConstraint.pm
index 1dfee28..093ede6 100644 (file)
@@ -7,9 +7,16 @@ with 'DX::Role::Op';
 has vars => (is => 'ro', required => 1);
 has constraint => (is => 'ro', required => 1);
 
+has _arg_map => (is => 'lazy', builder => sub {
+  my ($self) = @_;
+  my $name = 'arg0';
+  +{ map +($name++, $_), @{$self->vars} };
+});
+
 sub run {
   my ($self, $state) = @_;
-  my @vars = map $state->scope_var($_)->bound_value, @{$self->vars};
+  ($state, my %args) = $self->_expand_args($state, %{$self->_arg_map});
+  my @vars = map $_->bound_value, @args{sort keys %args};
   if ($self->constraint->(@vars)) {
     return $state->then($self->next);
   }