pervasive type constraints
[scpubgit/DX.git] / lib / DX / Types.pm
CommitLineData
3e465d5d 1package DX::Types;
2
3use strictures 2;
4use Type::Library
5 -base,
6 -declare => (
7 (our @CLASSES = qw(
8 Hypothesis Scope ResolvedPropositionSet Proposition DependencyMap
8c16d3c9 9 PropositionSequence QueryState ShellState ShellSession SearchState
839c0018 10 ResolutionSpace ResolutionStrategy Resolution
3e465d5d 11 )),
12 (our @ROLES = qw(
2548ce61 13 Step Action ActionPolicy Predicate Value ActionBuilder Update
3e465d5d 14 )),
15 qw(
d6fabec9 16 DependencyType _DependencyTree DependencySpec
2548ce61 17 One DependencyGroupEntry DependencyGroup ValuePath
3e465d5d 18 ),
19 )
20;
21use Type::Utils -all;
22use Types::Standard qw(
23 ArrayRef Tuple HashRef Dict Maybe Optional slurpy Str
24);
25use DX::Utils qw(:event_types :dep_types);
26
27foreach my $class (our @CLASSES) {
28 class_type $class => { class => 'DX::'.$class };
29}
30
31foreach my $role (our @ROLES) {
32 role_type $role => { role => 'DX::Role::'.$role };
33}
34
35class_type DictValue => { class => 'DX::Value::Dict' };
36
2548ce61 37declare ValuePath => as ArrayRef[Str];
38
d6fabec9 39declare PropositionList => as ArrayRef[Proposition];
40
1c02730b 41declare DecisionList => as ArrayRef[Tuple[ResolutionSpace, SearchState]];
3e465d5d 42
43declare DependencyType => where {
d5511afa 44 foreach my $cand (EXISTENCE_OF, TYPE_OF, INDICES_OF, CONTENTS_OF) {
3e465d5d 45 return 1 if $_ eq $cand;
46 }
47 return 0;
48};
49
50declare EventType => where {
51 foreach my $cand (VALUE_SET, VALUE_EXISTS) {
52 return 1 if $_ eq $cand;
53 }
54 return 0;
55};
56
57declare _DependencyTree => where { is_DependencyTree($_) };
58
59declare DependencySpec => as Tuple[DependencyType, slurpy ArrayRef[Str]];
60
d6fabec9 61declare DependencyList => as ArrayRef[DependencySpec];
62
3e465d5d 63declare One => where { !ref($_) and $_ eq 1 };
64
65declare DependencyTree => # [ \%subtree, \%existence_of, ... ]
66 as HashRef[Tuple[
67 Maybe[_DependencyTree],
68 (Optional[Maybe[HashRef[One]]]) x 4
69 ]];
70
9acbb80f 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];
3e465d5d 81
821;