1 package DX::Predicate::MemberAt;
3 use DX::Utils qw(step INDICES_OF EXISTENCE_OF CONTENTS_OF string);
4 use DX::ActionBuilder::ProxySetToAdd;
7 with 'DX::Role::Predicate';
9 # Thing I've ignored for the moment: set key, unset value
10 # which for an add should result in an _make_equal style
11 # bind-with-add-action I suspect, but I don't have a current use
12 # case so punting while I get everything-the-fuck-else done
14 sub _possible_resolution_list {
15 my ($self, $coll, $key, $value) = @_;
16 die "First argument to member_at must be a structured value"
17 unless $coll->does('DX::Role::StructuredValue');
20 ? map $_->but_with_dependencies_on(
22 [ EXISTENCE_OF ,=> $coll, $key->string_value ],
23 [ CONTENTS_OF ,=> $key ],
26 if (my $cur_val = $coll->get_member_at($key)) {
27 $self->_make_equal($cur_val, $value);
30 and my $add = $coll->action_for_add_member($key, $value)
36 [ CONTENTS_OF ,=> $coll, $key->string_value ],
37 [ CONTENTS_OF ,=> $value ],
43 and $value->action_builder->isa('DX::ActionBuilder::UnsetValue')
44 and my $p = $coll->identity_path
46 my @path = (@$p, $key->string_value);
47 my $ab = DX::ActionBuilder::ProxySetToAdd->new(
48 target_path => \@path,
49 proxy_to => $coll->action_builder,
51 my $set = $value->action_for_set_value(
53 identity_path => \@path,
61 [ CONTENTS_OF ,=> $coll, $key->string_value ],
62 [ CONTENTS_OF ,=> $value ],
74 my $set_key = $key->action_for_set_value(string(my $kstr = $_));
75 map $_->but_first($set_key)
76 ->but_with_dependencies_on(
78 [ EXISTENCE_OF ,=> $coll, $kstr ],
79 [ CONTENTS_OF ,=> $key ],
82 $self->_make_equal($coll->get_member_at($_), $value);
89 sub selection_depends_on {
90 my ($self, $coll, $key, $value) = @_;
92 [ [ $coll => ($key->can_set_value ? INDICES_OF : (EXISTENCE_OF ,=> $key)) ],