b34565ba14fcca3ad4e828e165fe6b6382f2532d
[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
14     )),
15     qw(
16       DependencyType _DependencyTree DependencySpec
17       One DependencyGroupEntry DependencyGroup
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 PropositionList => as ArrayRef[Proposition];
38
39 declare DecisionList => as ArrayRef[Tuple[ResolutionSpace, SearchState]];
40
41 declare DependencyType => where {
42   foreach my $cand (EXISTENCE_OF, TYPE_OF, INDICES_OF, CONTENTS_OF) {
43     return 1 if $_ eq $cand;
44   }
45   return 0;
46 };
47
48 declare EventType => where {
49   foreach my $cand (VALUE_SET, VALUE_EXISTS) {
50     return 1 if $_ eq $cand;
51   }
52   return 0;
53 };
54
55 declare _DependencyTree => where { is_DependencyTree($_) };
56
57 declare DependencySpec => as Tuple[DependencyType, slurpy ArrayRef[Str]];
58
59 declare DependencyList => as ArrayRef[DependencySpec];
60
61 declare One => where { !ref($_) and $_ eq 1 };
62
63 declare DependencyTree => # [ \%subtree, \%existence_of, ... ]
64   as HashRef[Tuple[
65        Maybe[_DependencyTree],
66        (Optional[Maybe[HashRef[One]]]) x 4
67      ]];
68
69 ## These were from the dependency group thing which makes no sense until
70 ## we have scoping, so revisit it then
71 #
72 #declare DependencyGroupEntry =>
73 #  as Tuple[DependencyType, slurpy ArrayRef[Value|Str]];
74 #
75 #declare DependencyGroup =>
76 #  as Tuple[Maybe[Value], slurpy ArrayRef[DependencyGroupEntry]];
77 #
78 #declare DependencyGroupList => as ArrayRef[DependencyGroup];
79
80 1;