package DX::Role::Op;

use Moo::Role;

has next => (is => 'ro');

requires 'run';

sub but {
  my ($self, @but) = @_;
  $self->new(%$self, @but);
}

sub _expand_args {
  my ($self, $state, %spec) = @_;
  my %args;
  @args{keys %spec} = map $self->_expand_argspec($state, $_), values %spec;
  return $state->expand_vars(%args);
}

sub _expand_argspec {
  my ($self, $state, $spec) = @_;
  if (!ref($spec)) {
    $state->scope_var($spec)
  } elsif (ref($spec) eq 'ARRAY') {
    if ($spec->[0] eq 'value') {
      +{ bound_value => $spec->[1] };
    } else {
      die "Arrayref in argspec is not value";
    }
  } else {
    die "Argspec incomprehensible";
  }
}


1;
