switchover to rspace next_step and dump step()
[scpubgit/DX.git] / lib / DX / Step / ResolveProposition.pm
index cb236d8..3416c27 100644 (file)
@@ -4,19 +4,47 @@ use DX::Step::EnterRecheck;
 use DX::Step::Backtrack;
 
 use Types::Standard qw(ArrayRef);
-use DX::Utils qw(deparse);
 
 use DX::Class;
 
 with 'DX::Role::Step';
 
-has actions => (is => 'ro', isa => ArrayRef[Action], required => 1);
-
-has depends_on => (is => 'ro', isa => DependencyGroupList, required => 1);
-
-has resolves => (is => 'ro', isa => Proposition);
+has resolves => (is => 'lazy', init_arg => undef, builder => sub {
+  my ($self) = @_;
+  $self->resolution_space->proposition;
+});
+
+has resolution_space => (is => 'ro', isa => ResolutionSpace);
+
+has current_resolution => (is => 'lazy', init_arg => undef, builder => sub {
+  my ($self) = @_;
+  $self->resolution_space->next_resolution;
+});
+
+has actions => (is => 'lazy', init_arg => undef, builder => sub {
+  my ($self) = @_;
+  $self->current_resolution->actions;
+});
+
+has depends_on => (is => 'lazy', init_arg => undef, builder => sub {
+  my ($self) = @_;
+  my $_expand_dep = sub {
+    my ($type, @path) = @{$_[0]};
+    my @expanded = map {
+      ref() ? @{$_->value_path or return ()} : $_
+    } @path;
+    return [ $type, @expanded ];
+  };
+  [ map $_expand_dep->($_),
+      @{$self->current_resolution->veracity_depends_on} ];
+});
 
-has alternative_step => (is => 'ro', isa => Step);
+has alternative_step => (is => 'lazy', init_arg => undef, builder => sub {
+  my ($self) = @_;
+  my $rspace = $self->resolution_space->remaining_resolution_space;
+  return undef unless @{$rspace->members};
+  return $rspace->next_step;
+});
 
 sub but_first {
   my ($self, @actions) = @_;
@@ -30,6 +58,30 @@ sub but_with_dependencies_on {
 
 sub apply_to {
   my ($self, $old_ss) = @_;
+  trace resolve => [ statement => [
+    [ symbol => 'resolve' ],
+    [ block => [
+      [ statement => [
+        [ symbol => 'proposition' ],
+        @{$self->resolves->for_deparse->[1]},
+      ] ],
+      (@{$self->actions}
+        ? [ statement => [
+            [ symbol => 'actions' ],
+            [ block => [ @{$self->actions} ] ],
+          ] ]
+        : ()),
+      [ statement => [
+        [ symbol => 'depends_on' ],
+        [ pairs => [
+          map [
+            (split '::', ${$_->[0]})[-1],
+            [ value_path => [ @{$_}[1..$#$_] ] ]
+          ], @{$self->depends_on}
+        ] ],
+      ] ],
+    ] ]
+  ] ];
   my $ns = do {
     if (my $prop = $old_ss->next_proposition) {
       DX::Step::ConsiderProposition->new(
@@ -39,13 +91,12 @@ sub apply_to {
       $old_ss->on_solution_step
     }
   };
-  my $alt_step = $self->alternative_step;
   my $ss = $old_ss->but(
     next_step => $ns,
-    ($alt_step
-      ? (alternatives => [
-          [ $old_ss->current_hypothesis, $alt_step ],
-          @{$old_ss->alternatives}
+    (@{$self->actions}
+      ? (adjustments_made => [
+          [ $self, $old_ss ],
+          @{$old_ss->adjustments_made}
         ])
       : ()
     ),