1 package DX::Predicate::MemberAt;
3 use DX::Utils qw(:builders :dep_types);
4 use DX::ActionBuilder::ProxySetToAdd;
5 use DX::ActionBuilder::Null;
8 with 'DX::Role::Predicate';
10 # member_at Dict Key Value
12 # Dict must be set to a dict (later maybe also an array and Key -> Index)
24 # Dict.Key != Value ->
30 # Set value to Dict.Key
32 # Key does not exist ->
38 # Failure on (exists Dict.Key, Value)
42 # Set value to ProxySetToAdd value
44 # Dict disallows add ->
46 # Failure on (exists Dict.Key)
50 # Value must also be unbound, because seriously?
52 # Set [Key, Value] to each pair in turn
54 sub _resolution_space_for {
55 my ($self, $dict, $key, $value) = @_;
57 die "Fucked" unless $dict->does('DX::Role::StructuredValue');
61 if (my $cur_val = $dict->get_member_at($key)) {
64 [ CONTENTS_OF ,=> $dict, $key->string_value ],
65 [ CONTENTS_OF ,=> $value ],
71 $cur_val->equals($value)
72 # Trivial resolution, D.K = V
75 veracity_depends_on => $deps,
82 geometry_depends_on => $deps,
89 geometry_depends_on => [
90 [ CONTENTS_OF ,=> $dict, $key->string_value ],
91 [ TYPE_OF ,=> $value ],
95 actions => [ $value->action_for_set_value($cur_val) ],
96 veracity_depends_on => $deps,
103 if ($dict->can_add_member) {
106 [ EXISTENCE_OF ,=> $dict, $key->string_value ],
107 [ TYPE_OF ,=> $value ],
110 if ($value->is_set) {
112 # If we get here, it means (currently) that we entered recheck
113 # due to the deletion of the key from the dict and should fail
114 # (or there's a bug in the compiler but let's hope not)
116 geometry_depends_on => $deps,
121 my @path = (@{$dict->value_path}, $key->string_value);
122 my $ab = DX::ActionBuilder::ProxySetToAdd->new(
123 target_path => \@path,
124 proxy_to => $dict->action_builder,
128 geometry_depends_on => $deps,
132 $value->action_for_set_value(
133 $value->but(action_builder => $ab),
136 # Veracity only depends on EXISTENCE_OF at this stage - if the
137 # $value is later set, recheck will lead us down a different path
138 # that will update those dependencies to include CONTENTS_OF
139 veracity_depends_on => $deps,
146 # Dict doesn't allow adding keys and key doesn't exist, so
147 # the contents of the value is completely irrelevant to the failure
149 geometry_depends_on => [
150 [ EXISTENCE_OF ,=> $dict, $key->string_value ],
157 die "Fucked" if $value->is_set; # +D -K +V ? seriously ?
159 # Laaater we may need to look at autovivifying an additional key/index
160 # ala ProxySetToAdd but I'm not 100% sure how that will make sense and
161 # premature generalisation is the root of all eval.
165 [ $dict->get_member_at($_) ],
166 ], map string($_), $dict->index_list;
169 geometry_depends_on => [
170 [ INDICES_OF ,=> $dict ],
171 [ TYPE_OF ,=> $key ],
172 [ TYPE_OF ,=> $value ],
176 action_prototypes => [
177 [ $key => 'set_value' ],
178 [ $value => 'set_value' ],
180 veracity_depends_on_builder => sub {
181 my ($this_key, $this_val) = map @$_, @_;
183 [ CONTENTS_OF ,=> $dict, $this_key->string_value ],
184 [ CONTENTS_OF ,=> $key ],
185 [ CONTENTS_OF ,=> $value ],
188 implementation_candidates => \@cand,