From: Matt S Trout Date: Tue, 11 Feb 2014 18:56:34 +0000 (+0000) Subject: use VarRef for derived bindings X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=165d0b2c5be60fd1244429aab0bf82795db83459;p=scpubgit%2FDKit.git use VarRef for derived bindings --- diff --git a/lib/DX/Op/Prop.pm b/lib/DX/Op/Prop.pm index dc4ae78..c2b494b 100644 --- a/lib/DX/Op/Prop.pm +++ b/lib/DX/Op/Prop.pm @@ -1,5 +1,6 @@ package DX::Op::Prop; +use DX::VarRef; use Moo; with 'DX::Role::Op'; @@ -31,7 +32,8 @@ sub run { if ($value->can("has_${name}") and not $value->${\"has_${name}"}) { return $state->backtrack; } - return $state->bind_value($args{value}->id, $value->$name) + my $var_ref = DX::VarRef->new(var_id => $args{of}->id, derive => $name); + return $state->bind_value($args{value}->id, $var_ref) ->add_dependencies($args{value}->id => $args{of}->id) ->then($self->next); } diff --git a/lib/DX/VarRef.pm b/lib/DX/VarRef.pm new file mode 100644 index 0000000..8b82db6 --- /dev/null +++ b/lib/DX/VarRef.pm @@ -0,0 +1,16 @@ +package DX::VarRef; + +use Moo; + +with 'DX::Role::Ref'; + +has var_id => (is => 'ro', required => 1); + +has derive => (is => 'ro', default => sub { $_[0] }); + +sub resolve { + my ($self, $state) = @_; + $state->resolve_value($state->by_id->{$self->var_id})->${\$self->derive}; +} + +1;