slightly less useless error on lack of variable
[scpubgit/DKit.git] / lib / DX / Result.pm
CommitLineData
deec7cc4 1package DX::Result;
2
9c7b21a2 3use Safe::Isa;
deec7cc4 4use Moo;
5
6has _state => (is => 'ro', required => 1, init_arg => 'state');
7
8sub var_names {
9 sort keys %{$_[0]->_state->scope};
10}
11
12sub actions {
13 my ($self) = @_;
9c7b21a2 14 my $state = $self->_state;
577a2146 15 my $actions = $state->actions;
16 my @act = @{$actions}{sort keys %$actions};
17 return @act; # separate array to get correct scalar context return
deec7cc4 18}
19
60c182d8 20sub independent_actions {
21 my ($self) = @_;
22 return grep !@{$_->dependencies}, $self->actions;
23}
24
25sub expand_action_dependencies {
deec7cc4 26 my ($self, $action) = @_;
27 my $by_id = $self->_state->by_id;
28 return map $by_id->{$_}->action, @{$action->dependencies};
29}
30
31sub value_for {
32 my ($self, $name) = @_;
0676b282 33 my $state = $self->_state;
34 $state->resolve_value($state->scope_var($name));
35}
36
37sub all_values {
38 my ($self) = @_;
39 return +{ map +($_ => $self->value_for($_)), $self->var_names };
deec7cc4 40}
41
421;