KeyMangler example app
[scpubgit/DKit.git] / lib / DX / RuleSet.pm
index baa9586..ba0f3c5 100644 (file)
@@ -14,8 +14,10 @@ use DX::Op::ProposeAction;
 use DX::Op::ModifyAction;
 use DX::Op::Materialize;
 use DX::Op::Prop;
-use DX::Op::Exists;
 use DX::Op::Predicate;
+use DX::Op::HasAction;
+use DX::Op::FindAll;
+use DX::Op::ForEach;
 use List::Util qw(reduce);
 
 has rules => (is => 'ro', default => sub { {} });
@@ -70,10 +72,28 @@ sub _expand_op_cut { return DX::Op::Cut->new }
 sub _expand_op_fail { return DX::Op::Backtrack->new }
 
 sub _expand_op_not {
-  my ($self, @contents) = @_;
+  my ($self, $contents) = @_;
   my $cut = DX::Op::Cut->new(next => DX::Op::Backtrack->new);
   DX::Op::Not->new(
-    body => $self->expand_and_link($cut, @contents)
+    body => $self->expand_and_link($cut, @$contents)
+  );
+}
+
+sub _expand_op_findall {
+  my ($self, $coll_name, $var_name, $contents) = @_;
+  DX::Op::FindAll->new(
+    coll_name => $coll_name,
+    var_name => $var_name,
+    body => $self->expand_and_link(DX::Op::Return->new, @$contents),
+  );
+}
+
+sub _expand_op_foreach {
+  my ($self, $var_name, $body, $each_body) = @_;
+  DX::Op::ForEach->new(
+    var_name => $var_name,
+    body => $self->expand_and_link(DX::Op::Return->new, @$body),
+    each_body => $self->expand_and_link(DX::Op::Return->new, @$each_body),
   );
 }
 
@@ -118,8 +138,8 @@ sub _expand_op_react {
 }
 
 sub _expand_op_materialize {
-  my ($self, $var_name) = @_;
-  DX::Op::Materialize->new(var_name => $var_name);
+  my ($self) = @_;
+  DX::Op::Materialize->new;
 }
 
 sub _expand_op_prop {
@@ -128,12 +148,9 @@ sub _expand_op_prop {
   DX::Op::Prop->new(%new);
 }
 
-sub _expand_op_exists {
-  my ($self, $vars, @body) = @_;
-  DX::Op::Exists->new(
-    vars => $vars,
-    body => $self->expand_and_link(DX::Op::Return->new, @body)
-  );
+sub _expand_op_has_action {
+  my ($self, @args) = @_;
+  DX::Op::HasAction->new(arg_spec => \@args);
 }
 
 1;