package DX::Op::ModifyAction;
+use Safe::Isa;
use DX::ObservationRequired;
use Moo;
my ($self, $state) = @_;
($state, my %args) = $self->_expand_args($state, %{$self->_arg_map});
my ($subject, @vars) = @args{sort keys %args};
- die "Can't alter action on $subject" unless
- my $orig_action = $state->resolve_value($subject)->required_action;
+ my $subject_fact = $state->resolve_value($subject);
+ die "Subject not a fact" unless $subject_fact->$_does('DX::Role::Fact');
+ die "Subject has no action" unless $subject_fact->has_required_action;
+ my $orig_action = $state->actions->{$subject_fact->required_action};
my @deps = $state->action_dependencies(
@{$orig_action->dependencies},
map $_->id, @vars
my $action = $self->builder->(@builder_args)
->but(dependencies => \@deps);
my ($fact_type, $value) = $action->expected_effect;
- my $final_value = $value->but(required_action => $action);
+ my $final_value = $value->but(required_action => $action->id);
my $fact_set = $state->facts->{$fact_type}->with_value($final_value);
- $state->but(facts => { %{$state->facts}, $fact_type => $fact_set })
+ $state->but(
+ facts => { %{$state->facts}, $fact_type => $fact_set },
+ actions => { %{$state->actions}, $action->id => $action },
+ )
->then($self->next);
}