From: Matt S Trout Date: Sat, 7 Apr 2018 19:30:34 +0000 (+0000) Subject: finish adding type constraints X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FDX.git;a=commitdiff_plain;h=cfae7810d594e9f9425e7c564c62f444f254fe43 finish adding type constraints --- diff --git a/lib/DX/ActionPolicy/LockScope.pm b/lib/DX/ActionPolicy/LockScope.pm index caa8b96..203ff1c 100644 --- a/lib/DX/ActionPolicy/LockScope.pm +++ b/lib/DX/ActionPolicy/LockScope.pm @@ -4,9 +4,9 @@ use DX::Class; with 'DX::Role::ActionPolicy'; -has lock_to_depth => (is => 'ro', required => 1); +has lock_to_depth => (is => 'ro', required => 1, isa => Int); -has next_policy => (is => 'ro', required => 1); +has next_policy => (is => 'ro', required => 1, isa => ActionPolicy); sub allows { my ($self, $action) = @_; diff --git a/lib/DX/DependencyMap.pm b/lib/DX/DependencyMap.pm index a38925f..d1b8eb2 100644 --- a/lib/DX/DependencyMap.pm +++ b/lib/DX/DependencyMap.pm @@ -9,7 +9,7 @@ use DX::Class; has deps => (is => 'ro', isa => DependencyTree, required => 1); -has revdeps => (is => 'ro', required => 1); +has revdeps => (is => 'ro', required => 1, isa => HashRef[DependencyList]); sub new_empty { my ($class) = @_; diff --git a/lib/DX/Expander.pm b/lib/DX/Expander.pm index 9f8639d..3cc74ee 100644 --- a/lib/DX/Expander.pm +++ b/lib/DX/Expander.pm @@ -3,11 +3,12 @@ package DX::Expander; use DX::Utils qw(:all); use DX::Value::True; use DX::Value::False; +use Types::Standard qw(InstanceOf); use Tcl; use DX::Class; has tcl => ( - is => 'lazy', builder => sub { Tcl->new }, + is => 'lazy', builder => sub { Tcl->new }, isa => InstanceOf['Tcl'], handles => { _split_list => 'SplitList' }, ); diff --git a/lib/DX/Predicate/Rule.pm b/lib/DX/Predicate/Rule.pm index c599ea5..9587770 100644 --- a/lib/DX/Predicate/Rule.pm +++ b/lib/DX/Predicate/Rule.pm @@ -4,8 +4,10 @@ use DX::Class; with 'DX::Role::Predicate'; -has arg_names => (is => 'ro', required => 1); +has arg_names => (is => 'ro', required => 1, isa => ArrayRef[Str]); -has proposition_sequence => (is => 'ro', required => 1); +has proposition_sequence => ( + is => 'ro', required => 1, isa => PropositionSequence +); 1; diff --git a/lib/DX/QueryState.pm b/lib/DX/QueryState.pm index b378783..cc438e7 100644 --- a/lib/DX/QueryState.pm +++ b/lib/DX/QueryState.pm @@ -18,13 +18,13 @@ has proposition_sequence => ( is => 'ro', isa => PropositionSequence, required => 1 ); -has search_state => ( - is => 'lazy', builder => sub { - $_[0]->new_search_state_for($_[0]->proposition_sequence) - }, +has search_process => ( + is => 'lazy', isa => SearchProcess, builder => sub { + $_[0]->new_search_process_for($_[0]->proposition_sequence) + }, handles => { search_state => 'current_search_state' }, ); -sub new_search_state_for { +sub new_search_process_for { my ($self, $prop_seq) = @_; my @local_names = map { keys %{$_->introduced_names} } @{$prop_seq->members}; @@ -59,20 +59,20 @@ sub with_additional_proposition { my ($self, $prop) = @_; my $prop_seq = $self->proposition_sequence ->with_additional_proposition($prop); - my $sol_ss = $self->new_search_state_for($prop_seq) + my $sol_ss = $self->new_search_process_for($prop_seq) ->find_solution; die "No solution\n" unless $sol_ss; $self->but( proposition_sequence => $prop_seq, - search_state => $sol_ss, + search_process => $sol_ss, ); } sub with_forced_backtrack { my ($self) = @_; - my $next_ss = $self->search_state->find_next_solution; + my $next_ss = $self->search_process->find_next_solution; die "No next solution\n" unless $next_ss; - $self->but(search_state => $next_ss); + $self->but(search_process => $next_ss); } 1; diff --git a/lib/DX/ResolutionStrategy.pm b/lib/DX/ResolutionStrategy.pm index 9deaa85..18126f0 100644 --- a/lib/DX/ResolutionStrategy.pm +++ b/lib/DX/ResolutionStrategy.pm @@ -17,15 +17,6 @@ has implementation_candidates => ( is => 'ro', required => 1, isa => ArrayRef[ArrayRef[ArrayRef[Value]]] ); -has aperture => (is => 'lazy', builder => sub { - my ($self) = @_; - return [ - # [ $thing, 'set_value' ] -> $thing->aperture_for_set_value - map @{$_->[0]->${\'aperture_for_'.$_[1]}()}, - @{$self->action_prototypes} - ]; -}); - sub next_resolution { my ($self) = @_; return undef unless my ($first) = @{$self->implementation_candidates}; diff --git a/lib/DX/RuleDefinitionContext.pm b/lib/DX/RuleDefinitionContext.pm index 6d192c2..308dd19 100644 --- a/lib/DX/RuleDefinitionContext.pm +++ b/lib/DX/RuleDefinitionContext.pm @@ -4,16 +4,21 @@ use DX::PropositionSequence; use DX::Predicate::Rule; use DX::Class; -has arg_names => (is => 'ro', required => 1); +has arg_names => (is => 'ro', required => 1, isa => ArrayRef[Str]); -has proposition_sequence => (is => 'rwp', lazy => 1, builder => sub { - my ($self) = @_; - my %arg_names = map +($_ => 1), @{$self->arg_names}; - DX::PropositionSequence->new_empty - ->but(external_names => \%arg_names); -}); +has proposition_sequence => ( + is => 'rwp', lazy => 1, isa => PropositionSequence, + builder => sub { + my ($self) = @_; + my %arg_names = map +($_ => 1), @{$self->arg_names}; + DX::PropositionSequence->new_empty + ->but(external_names => \%arg_names); + } +); -has expander => (is => 'ro', required => 1, handles => [ qw(expand_args) ]); +has expander => ( + is => 'ro', required => 1, isa => Expander, handles => [ qw(expand_args) ] +); sub apply_predicate { my ($self, $pred, @arg_strings) = @_; diff --git a/lib/DX/ShellFrontend.pm b/lib/DX/ShellFrontend.pm index 3c95506..74eac41 100644 --- a/lib/DX/ShellFrontend.pm +++ b/lib/DX/ShellFrontend.pm @@ -10,7 +10,7 @@ has session => ( handles => [ qw(is_complete_command_string eval_command_string) ] ); -has session_mode => (is => 'rwp', isa => Enum['shell','query'], required => 1); +has session_mode => (is => 'rwp', isa => ShellMode, required => 1); has readline => ( is => 'lazy', isa => InstanceOf['Caroline'], diff --git a/lib/DX/ShellSession.pm b/lib/DX/ShellSession.pm index 589117b..255a089 100644 --- a/lib/DX/ShellSession.pm +++ b/lib/DX/ShellSession.pm @@ -14,7 +14,7 @@ has shell_state => (is => 'rwp', required => 1, isa => ShellState); has expander => ( is => 'lazy', builder => sub { DX::Expander->new(tcl => $_[0]->tcl) }, - isa => InstanceOf['DX::Expander'], handles => [ qw(expand_args) ], + isa => Expander, handles => [ qw(expand_args) ], ); has tcl => (is => 'lazy', isa => InstanceOf['Tcl'], builder => sub { diff --git a/lib/DX/ShellState.pm b/lib/DX/ShellState.pm index 9f77143..c2e9fd2 100644 --- a/lib/DX/ShellState.pm +++ b/lib/DX/ShellState.pm @@ -8,14 +8,14 @@ has template_query_state => ( ); has current_query_state => ( - is => 'lazy', builder => 'new_query_state' + is => 'lazy', builder => 'new_query_state', isa => QueryState ); has trace_these => ( - is => 'ro', required => 1, + is => 'ro', required => 1, isa => HashRef[Str], ); -has mode => (is => 'ro', required => 1); +has mode => (is => 'ro', required => 1, isa => ShellMode); sub new_query_state { $_[0]->template_query_state } diff --git a/lib/DX/Types.pm b/lib/DX/Types.pm index 2482f01..627efe6 100644 --- a/lib/DX/Types.pm +++ b/lib/DX/Types.pm @@ -7,7 +7,7 @@ use Type::Library (our @CLASSES = qw( Hypothesis Scope ResolvedPropositionSet Proposition DependencyMap PropositionSequence QueryState ShellState ShellSession SearchState - ResolutionSpace ResolutionStrategy Resolution + ResolutionSpace ResolutionStrategy Resolution Expander SearchProcess )), (our @ROLES = qw( Step Action ActionPolicy Predicate Value ActionBuilder Update @@ -15,13 +15,13 @@ use Type::Library qw( DependencyType _DependencyTree DependencySpec One DependencyGroupEntry DependencyGroup ValuePath - EventType ApertureList DependencyList + EventType ApertureList DependencyList ShellMode ), ) ; use Type::Utils -all; use Types::Standard qw( - ArrayRef Tuple HashRef Dict Maybe Optional slurpy Str + ArrayRef Tuple HashRef Dict Maybe Optional slurpy Str Enum ); use DX::Utils qw(:event_types :dep_types); @@ -71,6 +71,8 @@ declare DependencyTree => # [ \%subtree, \%existence_of, ... ] declare ApertureList => as ArrayRef[Tuple[EventType, slurpy ValuePath]]; +declare ShellMode => as Enum[qw(shell query)]; + ## These were from the dependency group thing which makes no sense until ## we have scoping, so revisit it then #