fully type Resolution* classes
[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       EventType ApertureList DependencyList
19     ),
20   )
21 ;
22 use Type::Utils -all;
23 use Types::Standard qw(
24   ArrayRef Tuple HashRef Dict Maybe Optional slurpy Str
25 );
26 use DX::Utils qw(:event_types :dep_types);
27
28 foreach my $class (our @CLASSES) {
29   class_type $class => { class => 'DX::'.$class };
30 }
31
32 foreach my $role (our @ROLES) {
33   role_type $role => { role => 'DX::Role::'.$role };
34 }
35
36 class_type DictValue => { class => 'DX::Value::Dict' };
37
38 declare ValuePath => as ArrayRef[Str];
39
40 declare PropositionList => as ArrayRef[Proposition];
41
42 declare DecisionList => as ArrayRef[Tuple[ResolutionSpace, SearchState]];
43
44 declare DependencyType => where {
45   foreach my $cand (EXISTENCE_OF, TYPE_OF, INDICES_OF, CONTENTS_OF) {
46     return 1 if $_ eq $cand;
47   }
48   return 0;
49 };
50
51 declare EventType => where {
52   foreach my $cand (VALUE_SET, VALUE_EXISTS) {
53     return 1 if $_ eq $cand;
54   }
55   return 0;
56 };
57
58 declare _DependencyTree => where { is_DependencyTree($_) };
59
60 declare DependencySpec => as Tuple[DependencyType, slurpy ValuePath];
61
62 declare DependencyList => as ArrayRef[DependencySpec];
63
64 declare One => where { !ref($_) and $_ eq 1 };
65
66 declare DependencyTree => # [ \%subtree, \%existence_of, ... ]
67   as HashRef[Tuple[
68        Maybe[_DependencyTree],
69        (Optional[Maybe[HashRef[One]]]) x 4
70      ]];
71
72 declare ApertureList => as ArrayRef[Tuple[EventType, slurpy ValuePath]];
73
74 ## These were from the dependency group thing which makes no sense until
75 ## we have scoping, so revisit it then
76 #
77 #declare DependencyGroupEntry =>
78 #  as Tuple[DependencyType, slurpy ArrayRef[Value|Str]];
79 #
80 #declare DependencyGroup =>
81 #  as Tuple[Maybe[Value], slurpy ArrayRef[DependencyGroupEntry]];
82 #
83 #declare DependencyGroupList => as ArrayRef[DependencyGroup];
84
85 1;