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