pervasive type constraints
[scpubgit/DX.git] / lib / DX / Types.pm
1 package DX::Types;
2
3 use strictures 2;
4 use Type::Library
5   -base,
6   -declare => (
7     (our @CLASSES = qw(
8       Hypothesis Scope ResolvedPropositionSet Proposition DependencyMap
9       PropositionSequence QueryState ShellState ShellSession SearchState
10       ResolutionSpace ResolutionStrategy Resolution
11     )),
12     (our @ROLES = qw(
13       Step Action ActionPolicy Predicate Value ActionBuilder Update
14     )),
15     qw(
16       DependencyType _DependencyTree DependencySpec
17       One DependencyGroupEntry DependencyGroup ValuePath
18     ),
19   )
20 ;
21 use Type::Utils -all;
22 use Types::Standard qw(
23   ArrayRef Tuple HashRef Dict Maybe Optional slurpy Str
24 );
25 use DX::Utils qw(:event_types :dep_types);
26
27 foreach my $class (our @CLASSES) {
28   class_type $class => { class => 'DX::'.$class };
29 }
30
31 foreach my $role (our @ROLES) {
32   role_type $role => { role => 'DX::Role::'.$role };
33 }
34
35 class_type DictValue => { class => 'DX::Value::Dict' };
36
37 declare ValuePath => as ArrayRef[Str];
38
39 declare PropositionList => as ArrayRef[Proposition];
40
41 declare DecisionList => as ArrayRef[Tuple[ResolutionSpace, SearchState]];
42
43 declare DependencyType => where {
44   foreach my $cand (EXISTENCE_OF, TYPE_OF, INDICES_OF, CONTENTS_OF) {
45     return 1 if $_ eq $cand;
46   }
47   return 0;
48 };
49
50 declare EventType => where {
51   foreach my $cand (VALUE_SET, VALUE_EXISTS) {
52     return 1 if $_ eq $cand;
53   }
54   return 0;
55 };
56
57 declare _DependencyTree => where { is_DependencyTree($_) };
58
59 declare DependencySpec => as Tuple[DependencyType, slurpy ArrayRef[Str]];
60
61 declare DependencyList => as ArrayRef[DependencySpec];
62
63 declare One => where { !ref($_) and $_ eq 1 };
64
65 declare DependencyTree => # [ \%subtree, \%existence_of, ... ]
66   as HashRef[Tuple[
67        Maybe[_DependencyTree],
68        (Optional[Maybe[HashRef[One]]]) x 4
69      ]];
70
71 ## These were from the dependency group thing which makes no sense until
72 ## we have scoping, so revisit it then
73 #
74 #declare DependencyGroupEntry =>
75 #  as Tuple[DependencyType, slurpy ArrayRef[Value|Str]];
76 #
77 #declare DependencyGroup =>
78 #  as Tuple[Maybe[Value], slurpy ArrayRef[DependencyGroupEntry]];
79 #
80 #declare DependencyGroupList => as ArrayRef[DependencyGroup];
81
82 1;