better naming and help command for KeyMangler
[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 {
7d384eca 9 grep $_[0]->_state->scope_var($_)->is_bound,
10 sort keys %{$_[0]->_state->scope};
deec7cc4 11}
12
13sub actions {
14 my ($self) = @_;
9c7b21a2 15 my $state = $self->_state;
577a2146 16 my $actions = $state->actions;
17 my @act = @{$actions}{sort keys %$actions};
18 return @act; # separate array to get correct scalar context return
deec7cc4 19}
20
60c182d8 21sub independent_actions {
22 my ($self) = @_;
23 return grep !@{$_->dependencies}, $self->actions;
24}
25
26sub expand_action_dependencies {
deec7cc4 27 my ($self, $action) = @_;
28 my $by_id = $self->_state->by_id;
29 return map $by_id->{$_}->action, @{$action->dependencies};
30}
31
32sub value_for {
33 my ($self, $name) = @_;
0676b282 34 my $state = $self->_state;
35 $state->resolve_value($state->scope_var($name));
36}
37
38sub all_values {
39 my ($self) = @_;
40 return +{ map +($_ => $self->value_for($_)), $self->var_names };
deec7cc4 41}
42
431;