From: Matt S Trout Date: Tue, 11 Feb 2014 14:35:56 +0000 (+0000) Subject: indirect via resolve_value method X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0676b2822d7fdcab673d3f0c4a85fe9d05af8a76;p=scpubgit%2FDKit.git indirect via resolve_value method --- diff --git a/lib/DX/Op/ApplyConstraint.pm b/lib/DX/Op/ApplyConstraint.pm index 093ede6..4d073db 100644 --- a/lib/DX/Op/ApplyConstraint.pm +++ b/lib/DX/Op/ApplyConstraint.pm @@ -16,7 +16,7 @@ has _arg_map => (is => 'lazy', builder => sub { sub run { my ($self, $state) = @_; ($state, my %args) = $self->_expand_args($state, %{$self->_arg_map}); - my @vars = map $_->bound_value, @args{sort keys %args}; + my @vars = map $state->resolve_value($_), @args{sort keys %args}; if ($self->constraint->(@vars)) { return $state->then($self->next); } diff --git a/lib/DX/Op/CallRule.pm b/lib/DX/Op/CallRule.pm index 17deac0..7702009 100644 --- a/lib/DX/Op/CallRule.pm +++ b/lib/DX/Op/CallRule.pm @@ -26,7 +26,7 @@ sub run { my $invoke = DX::Op::FromCode->new( code => sub { my ($self, $state) = @_; - my $call = $var->bound_value->but(args => \@args); + my $call = $state->resolve_value($var)->but(args => \@args); $state->but(scope => {})->then($call); } ); diff --git a/lib/DX/Op/Materialize.pm b/lib/DX/Op/Materialize.pm index beb15f8..7b52715 100644 --- a/lib/DX/Op/Materialize.pm +++ b/lib/DX/Op/Materialize.pm @@ -8,7 +8,7 @@ has var_name => (is => 'ro', required => 1); sub run { my ($self, $state) = @_; - $state->scope_var($self->var_name)->bound_value; + $state->resolve_value($state->scope_var($self->var_name)); $state->then($self->next); } diff --git a/lib/DX/Op/MemberOf.pm b/lib/DX/Op/MemberOf.pm index e5e9ca4..7b16482 100644 --- a/lib/DX/Op/MemberOf.pm +++ b/lib/DX/Op/MemberOf.pm @@ -16,7 +16,7 @@ sub run { ); my ($member, $of) = @args{qw(member of)}; die "member bound" if $member->is_bound; - my $set = $state->facts->{$of->bound_value}; + my $set = $state->facts->{$state->resolve_value($of)}; return $state->then($self->next) ->add_dependencies($member->id, $of->id) ->bind_root_set($member->id, $set) diff --git a/lib/DX/Op/Not.pm b/lib/DX/Op/Not.pm index f1bea19..90d99da 100644 --- a/lib/DX/Op/Not.pm +++ b/lib/DX/Op/Not.pm @@ -19,7 +19,7 @@ sub run { my $invoke = DX::Op::FromCode->new( code => sub { my ($self, $state) = @_; - my $op = $var->bound_value; + my $op = $state->resolve_value($var); $state->then($op); } ); diff --git a/lib/DX/Op/Observe.pm b/lib/DX/Op/Observe.pm index c458d2c..d264be5 100644 --- a/lib/DX/Op/Observe.pm +++ b/lib/DX/Op/Observe.pm @@ -17,7 +17,7 @@ has _arg_map => (is => 'lazy', builder => sub { sub run { my ($self, $state) = @_; ($state, my %args) = $self->_expand_args($state, %{$self->_arg_map}); - my @vars = map $_->bound_value, @args{sort keys %args}; + my @vars = map $state->resolve_value($_), @args{sort keys %args}; my $observer = $self->builder->(@vars); $state->return_from_run( DX::ObservationRequired->new( diff --git a/lib/DX/Op/Predicate.pm b/lib/DX/Op/Predicate.pm index 6971199..80a42b6 100644 --- a/lib/DX/Op/Predicate.pm +++ b/lib/DX/Op/Predicate.pm @@ -20,7 +20,7 @@ sub run { foreach my $i (0..$#arg_names) { if ($req->[$i] eq '+') { next CASE unless $args[$i]->is_bound; - $_{$arg_names[$i]} = $args[$i]->bound_value; + $_{$arg_names[$i]} = $state->resolve_value($args[$i]); } elsif ($req->[$i] eq '-') { next CASE if $args[$i]->is_bound; } diff --git a/lib/DX/Op/Prop.pm b/lib/DX/Op/Prop.pm index bacdf7c..dc4ae78 100644 --- a/lib/DX/Op/Prop.pm +++ b/lib/DX/Op/Prop.pm @@ -14,10 +14,11 @@ sub run { $state, map +($_ => $self->$_), qw(of name value) ); die "property name must be bound" unless $args{name}->is_bound; - my $name = $args{name}->bound_value; + my $name = $state->resolve_value($args{name}); if ($args{of}->is_bound) { if ($args{value}->is_bound) { - if ($args{of}->bound_value->$name eq $args{value}->bound_value) { + if ($state->resolve_value($args{of})->$name + eq $state->resolve_value($args{value})) { return $state->add_dependencies( $args{of}->id => $args{value}->id, $args{value}->id => $args{of}->id, @@ -26,7 +27,7 @@ sub run { } return $state->backtrack; } - my $value = $args{of}->bound_value; + my $value = $state->resolve_value($args{of}); if ($value->can("has_${name}") and not $value->${\"has_${name}"}) { return $state->backtrack; } diff --git a/lib/DX/Result.pm b/lib/DX/Result.pm index 2e49cf7..85d6774 100644 --- a/lib/DX/Result.pm +++ b/lib/DX/Result.pm @@ -27,7 +27,13 @@ sub expand_action_dependencies { sub value_for { my ($self, $name) = @_; - $self->_state->scope_var($name)->bound_value; + my $state = $self->_state; + $state->resolve_value($state->scope_var($name)); +} + +sub all_values { + my ($self) = @_; + return +{ map +($_ => $self->value_for($_)), $self->var_names }; } 1; diff --git a/lib/DX/Solver.pm b/lib/DX/Solver.pm index 0f23c54..6626840 100644 --- a/lib/DX/Solver.pm +++ b/lib/DX/Solver.pm @@ -14,7 +14,7 @@ has rule_set => ( }, ); -has facts => (is => 'ro', required => 1); +has facts => (is => 'ro', default => sub { {} }); has observation_policy => (is => 'ro'); diff --git a/lib/DX/State.pm b/lib/DX/State.pm index c677ce0..d397958 100644 --- a/lib/DX/State.pm +++ b/lib/DX/State.pm @@ -28,6 +28,11 @@ sub scope_var { $self->by_id->{$self->scope->{$name}}; } +sub resolve_value { + my ($self, $var) = @_; + $var->bound_value; +} + sub allocate_var { my ($self, $name, $var, $id_gen) = @_; my $id = join('_', $name, ++($id_gen->{$name}||='000'));