introduce root set
[scpubgit/DKit.git] / lib / DX / Var.pm
index d17f375..2a1f83c 100644 (file)
@@ -4,7 +4,15 @@ use Moo;
 
 has id => (is => 'ro', required => 1);
 
-has bound_stream => (is => 'ro');
+has root_set => (is => 'ro', predicate => 1);
+
+has bound_stream => (
+  is => 'lazy', predicate => 1, clearer => 1,
+  builder => sub {
+    my ($self) = @_;
+    $self->root_set->to_stream;
+  }
+);
 
 has bound_value => (is => 'lazy', predicate => 1, clearer => 1, builder => sub {
   if (defined(my $next = $_[0]->bound_stream->next)) {
@@ -18,7 +26,7 @@ has action => (is => 'ro');
 
 sub is_bound {
   my ($self) = @_;
-  $self->has_bound_value || $self->bound_stream;
+  $self->has_bound_value || $self->has_bound_stream || $self->has_root_set;
 }
 
 sub with_stream {
@@ -36,6 +44,11 @@ sub with_action {
   $self->new(%$self, action => $action);
 }
 
+sub with_root_set {
+  my ($self, $set) = @_;
+  $self->new(%$self, root_set => $set);
+}
+
 sub copy {
   my ($self) = @_;
   ref($self)->new(%$self);