4a5628a13c076781caf913b8713f657355a6ce6e
[scpubgit/DX.git] / lib / DX / Predicate / Dict.pm
1 package DX::Predicate::Dict;
2
3 use DX::Utils qw(step dict TYPE_OF);
4 use DX::Class;
5
6 with 'DX::Role::Predicate';
7
8 sub _possible_resolution_list {
9   my ($self, $arg, $proto) = @_;
10   if ($arg->is_set) {
11     die "dict called with non-dict"
12       unless $arg->isa('DX::Value::Dict');
13     return step(
14       actions => [],
15       depends_on => [ [ undef ,=> [ TYPE_OF ,=> $arg ] ] ]
16     );
17   }
18   if ($proto and not $proto->isa('DX::Value::Dict')) {
19     die "dict called with non-dict prototype";
20   }
21   my $set = $arg->action_for_set_value($proto||dict());
22   return step(
23     actions => [ $set ],
24     depends_on => [ [ undef ,=> [ TYPE_OF ,=> $arg ] ] ]
25   );
26 }
27
28 1;