Commit | Line | Data |
deec7cc4 |
1 | package DX::Result; |
2 | |
9c7b21a2 |
3 | use Safe::Isa; |
deec7cc4 |
4 | use Moo; |
5 | |
6 | has _state => (is => 'ro', required => 1, init_arg => 'state'); |
7 | |
8 | sub var_names { |
9 | sort keys %{$_[0]->_state->scope}; |
10 | } |
11 | |
12 | sub 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 |
20 | sub independent_actions { |
21 | my ($self) = @_; |
22 | return grep !@{$_->dependencies}, $self->actions; |
23 | } |
24 | |
25 | sub 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 | |
31 | sub value_for { |
32 | my ($self, $name) = @_; |
0676b282 |
33 | my $state = $self->_state; |
34 | $state->resolve_value($state->scope_var($name)); |
35 | } |
36 | |
37 | sub all_values { |
38 | my ($self) = @_; |
39 | return +{ map +($_ => $self->value_for($_)), $self->var_names }; |
deec7cc4 |
40 | } |
41 | |
42 | 1; |