pervasive type constraints
[scpubgit/DX.git] / lib / DX / Proposition.pm
1 package DX::Proposition;
2
3 use DX::Class;
4
5 has predicate => (is => 'ro', isa => Str, required => 1);
6
7 has args => (is => 'ro', isa => ArrayRef[Str|Value], required => 1);
8
9 has introduced_names => (is => 'ro', isa => HashRef[One], required => 1);
10
11 has required_names => (is => 'ro', isa => HashRef[One], required => 1);
12
13 sub for_deparse {
14   my ($self) = @_;
15   [ statement => [
16     [ symbol => $self->predicate ],
17     map {
18       ref($_)
19         ? $_
20         : [ symbol => $self->introduced_names->{$_} ? "?$_" : $_ ]
21     } @{$self->args}
22   ] ];
23 }
24
25 sub resolve_for {
26   my ($self, $scope) = @_;
27   my $predicate = $scope->lookup_predicate($self->predicate);
28   my @args = map { ref($_) ? $_ : $scope->lookup($_) } @{$self->args};
29   #if (my $step = $scope->known_facts->resolution_step_for($predicate, @args)) {
30   #  return $step;
31   #}
32   return $predicate->resolution_step_for($self, @args);
33 }
34
35 1;