types and deparsing and recalculation part working
[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     )),
10     (our @ROLES = qw(
11       Step Action ActionPolicy Predicate Value
12     )),
13     qw(
14       DependencyType _DependencyTree DependecySpec
15       One DependencyGroupEntry DependencyGroup
16     ),
17   )
18 ;
19 use Type::Utils -all;
20 use Types::Standard qw(
21   ArrayRef Tuple HashRef Dict Maybe Optional slurpy Str
22 );
23 use DX::Utils qw(:event_types :dep_types);
24
25 foreach my $class (our @CLASSES) {
26   class_type $class => { class => 'DX::'.$class };
27 }
28
29 foreach my $role (our @ROLES) {
30   role_type $role => { role => 'DX::Role::'.$role };
31 }
32
33 class_type DictValue => { class => 'DX::Value::Dict' };
34
35 declare AlternativeList => as ArrayRef[Tuple[Hypothesis, Step]];
36
37 declare DependencyType => where {
38   foreach my $cand (EXISTENCE_OF, INDICES_OF, TYPE_OF, CONTENTS_OF) {
39     return 1 if $_ eq $cand;
40   }
41   return 0;
42 };
43
44 declare EventType => where {
45   foreach my $cand (VALUE_SET, VALUE_EXISTS) {
46     return 1 if $_ eq $cand;
47   }
48   return 0;
49 };
50
51 declare _DependencyTree => where { is_DependencyTree($_) };
52
53 declare DependencySpec => as Tuple[DependencyType, slurpy ArrayRef[Str]];
54
55 declare One => where { !ref($_) and $_ eq 1 };
56
57 declare DependencyTree => # [ \%subtree, \%existence_of, ... ]
58   as HashRef[Tuple[
59        Maybe[_DependencyTree],
60        (Optional[Maybe[HashRef[One]]]) x 4
61      ]];
62
63 declare DependencyGroupEntry =>
64   as Tuple[DependencyType, slurpy ArrayRef[Value|Str]];
65
66 declare DependencyGroup =>
67   as Tuple[Maybe[Value], slurpy ArrayRef[DependencyGroupEntry]];
68
69 declare DependencyGroupList => as ArrayRef[DependencyGroup];
70
71 1;