From: Matt S Trout Date: Sat, 7 Apr 2018 18:20:32 +0000 (+0000) Subject: move dep expansion into predicates for the moment X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fe5af11f90482c9f5bdf74cd1f7699849451e211;p=scpubgit%2FDX.git move dep expansion into predicates for the moment --- diff --git a/lib/DX/Predicate/Dict.pm b/lib/DX/Predicate/Dict.pm index 3218e57..eba22f6 100644 --- a/lib/DX/Predicate/Dict.pm +++ b/lib/DX/Predicate/Dict.pm @@ -1,6 +1,6 @@ package DX::Predicate::Dict; -use DX::Utils qw(rspace res dict TYPE_OF); +use DX::Utils qw(rspace res dict TYPE_OF expand_deps); use DX::Class; with 'DX::Role::Predicate'; @@ -14,7 +14,7 @@ sub _resolution_space_for { die "dict called with non-dict prototype" if $proto and not $proto->isa('DX::Value::Dict'); - my $deps = [ [ TYPE_OF ,=> $arg ] ]; + my $deps = expand_deps([ [ TYPE_OF ,=> $arg ] ]); my $actions = $arg->is_set ? [] : [ $arg->action_for_set_value($proto||dict()) ]; diff --git a/lib/DX/Predicate/Eq.pm b/lib/DX/Predicate/Eq.pm index e0b3899..6f1db99 100644 --- a/lib/DX/Predicate/Eq.pm +++ b/lib/DX/Predicate/Eq.pm @@ -1,6 +1,6 @@ package DX::Predicate::Eq; -use DX::Utils qw(rspace res CONTENTS_OF); +use DX::Utils qw(rspace res CONTENTS_OF expand_deps); use DX::Class; with 'DX::Role::Predicate'; @@ -8,7 +8,9 @@ with 'DX::Role::Predicate'; sub _resolution_space_for { my ($self, $left, $right) = @_; - my $deps = [ [ CONTENTS_OF ,=> $left ], [ CONTENTS_OF ,=> $right ] ]; + my $deps = expand_deps([ + [ CONTENTS_OF ,=> $left ], [ CONTENTS_OF ,=> $right ] + ]); my $aperture = [ map @{$_->aperture_for_set_value}, $left, $right ]; diff --git a/lib/DX/Predicate/MemberAt.pm b/lib/DX/Predicate/MemberAt.pm index 491b48e..72d6018 100644 --- a/lib/DX/Predicate/MemberAt.pm +++ b/lib/DX/Predicate/MemberAt.pm @@ -1,6 +1,6 @@ package DX::Predicate::MemberAt; -use DX::Utils qw(:builders :dep_types); +use DX::Utils qw(:builders :dep_types expand_deps); use DX::ActionBuilder::ProxySetToAdd; use DX::ActionBuilder::Null; use DX::Class; @@ -60,10 +60,10 @@ sub _resolution_space_for { if (my $cur_val = $dict->get_member_at($key)) { - my $deps = [ + my $deps = expand_deps([ [ CONTENTS_OF ,=> $dict, $key->string_value ], [ CONTENTS_OF ,=> $value ], - ]; + ]); if ($value->is_set) { @@ -87,10 +87,10 @@ sub _resolution_space_for { } return rspace( - geometry_depends_on => [ + geometry_depends_on => expand_deps([ [ CONTENTS_OF ,=> $dict, $key->string_value ], [ TYPE_OF ,=> $value ], - ], + ]), aperture => $value->aperture_for_set_value, members => [ res( @@ -104,10 +104,10 @@ sub _resolution_space_for { if ($dict->can_add_member) { - my $deps = [ + my $deps = expand_deps([ [ EXISTENCE_OF ,=> $dict, $key->string_value ], [ TYPE_OF ,=> $value ], - ]; + ]); if ($value->is_set) { @@ -149,9 +149,9 @@ sub _resolution_space_for { # Dict doesn't allow adding keys and key doesn't exist, so # the contents of the value is completely irrelevant to the failure return rspace( - geometry_depends_on => [ + geometry_depends_on => expand_deps([ [ EXISTENCE_OF ,=> $dict, $key->string_value ], - ], + ]), aperture => [], members => [], ); @@ -170,11 +170,11 @@ sub _resolution_space_for { ], map string($_), $dict->index_list; return rspace( - geometry_depends_on => [ + geometry_depends_on => expand_deps([ [ INDICES_OF ,=> $dict ], [ TYPE_OF ,=> $key ], [ TYPE_OF ,=> $value ], - ], + ]), aperture => [ map @{$_->aperture_for_set_value}, $key, $value ], members => [ rstrat( @@ -184,11 +184,11 @@ sub _resolution_space_for { ], veracity_depends_on_builder => sub { my ($this_key, $this_val) = map @$_, @_; - return [ + return expand_deps([ [ CONTENTS_OF ,=> $dict, $this_key->string_value ], [ CONTENTS_OF ,=> $key ], [ CONTENTS_OF ,=> $value ], - ]; + ]); }, implementation_candidates => \@cand, ), diff --git a/lib/DX/Step/ResolveProposition.pm b/lib/DX/Step/ResolveProposition.pm index a064b5f..acd38d5 100644 --- a/lib/DX/Step/ResolveProposition.pm +++ b/lib/DX/Step/ResolveProposition.pm @@ -9,34 +9,15 @@ use DX::Class; with 'DX::Role::Step'; -has resolves => (is => 'lazy', init_arg => undef, builder => sub { - my ($self) = @_; - $self->resolution_space->proposition; -}); - has resolution_space => (is => 'ro', isa => ResolutionSpace); -has current_resolution => (is => 'lazy', init_arg => undef, builder => sub { - my ($self) = @_; - $self->resolution_space->next_resolution; -}); - -has actions => (is => 'lazy', init_arg => undef, builder => sub { - my ($self) = @_; - $self->current_resolution->actions; -}); - -has depends_on => (is => 'lazy', init_arg => undef, builder => sub { - my ($self) = @_; - expand_deps($self->current_resolution->veracity_depends_on); -}); - -has alternative_step => (is => 'lazy', init_arg => undef, builder => sub { - my ($self) = @_; - my $rspace = $self->resolution_space->remaining_resolution_space; - return undef unless @{$rspace->members}; - return $rspace->next_step; -}); +sub resolves { shift->resolution_space->proposition } + +sub current_resolution { shift->resolution_space->next_resolution } + +sub actions { shift->current_resolution->actions } + +sub depends_on { shift->current_resolution->veracity_depends_on } sub but_first { my ($self, @actions) = @_;