make MemberOf handle a bound RHS
Matt S Trout [Fri, 14 Feb 2014 19:54:10 +0000 (19:54 +0000)]
lib/DX/Op/MemberOf.pm

index 65f4511..cb9239d 100644 (file)
@@ -16,10 +16,21 @@ sub run {
     of => $self->coll_var
   );
   my ($member, $of) = @args{qw(member of)};
-  die "member bound" if $member->is_bound;
-  my $set = $state->facts->{my $type = $state->resolve_value($of)};
-  my $ref_set = DX::RefSet->new(
-    target => $type, names => [ $set->key_list ],
+  my $type = $state->resolve_value($of);
+  my $set = ref($type) ? $type : $state->facts->{$type};
+  if ($member->is_bound) {
+    my $test = $state->resolve_value($member);
+    if (grep { $_ eq $test } $set->all) {
+      return $state->then($self->next);
+    }
+    return $state->backtrack;
+  }
+  my $ref_set = (
+    ref($type)
+      ? $set
+      : DX::RefSet->new(
+          target => $type, names => [ $set->key_list ],
+        )
   );
   return $state->then($self->next)
                ->add_dependencies($member->id, $of->id)