add types to Proposition and PropositionSequence
[scpubgit/DX.git] / lib / DX / PropositionSequence.pm
CommitLineData
9eedd677 1package DX::PropositionSequence;
2
a97779a1 3use Types::Standard qw(HashRef);
9eedd677 4use DX::Class;
5
a97779a1 6has members => (is => 'ro', isa => PropositionList, required => 1);
9eedd677 7
a97779a1 8has external_names => (is => 'ro', isa => HashRef[One], required => 1);
5f12a9d8 9
a97779a1 10has internal_names => (is => 'ro', isa => HashRef[One], required => 1);
5f12a9d8 11
9eedd677 12sub new_empty {
5f12a9d8 13 shift->new(
14 members => [],
15 external_names => {},
16 internal_names => {},
17 );
9eedd677 18}
19
5f12a9d8 20sub with_additional_proposition {
9eedd677 21 my ($self, $prop) = @_;
5f12a9d8 22 my %already_names = (
23 %{$self->external_names}, %{$self->internal_names}
24 );
25 my @fail;
26 if (
27 my @missing = grep !$already_names{$_}, sort keys %{$prop->required_names}
28 ) {
29 push @fail,
30 " variables ".join(' ', @missing)." required but not in scope";
31 }
32 if (
33 my @shadow = grep $already_names{$_}, keys %{$prop->introduced_names}
34 ) {
35 push @fail,
36 " new variables ".join(' ', @shadow)." are already in scope";
37 }
38 if (@fail) {
39 die join("\n", "Can't add call to ${\$prop->predicate}:", @fail, '');
40 }
41 $self->but(
42 members => [ @{$self->members}, $prop ],
43 internal_names => { %{$self->internal_names}, %{$prop->introduced_names} },
44 );
9eedd677 45}
46
471;