3 use aliased 'DX::Op::FromCode';
4 use aliased 'DX::ArrayStream';
7 use DX::ObservationRequired;
10 '/home/me/.ssh' => { is_directory => 1 },
11 '/home/me/.ssh/authorized_keys' => { is_file => 1 },
13 my %paths = %observe_path;
15 my $set_dot_ssh = FromCode->new(
17 my ($self, $state) = @_;
18 $state->bind_var_then($state->scope_var('P'), '/home/me/.ssh', $self->next);
22 my $path_status = FromCode->new(
24 my ($self, $state) = @_;
25 if (my $p = $paths{$state->scope_var('P')->bound_value}) {
26 return $state->bind_var_then($state->scope_var('PS'), $p, $self->next);
28 return $state->backtrack;
32 my $check_dir = FromCode->new(
34 my ($self, $state) = @_;
35 if ($state->scope_var('PS')->bound_value->{is_directory}) {
36 return $state->then($self->next);
38 return $state->backtrack;
45 my %scope = map +($_ => $_), @{$vars};
46 my %by_id = map +($_ => DX::Var->new(id => $_)), @{$vars};
57 my $state = make_state([ 'P', 'PS' ],
59 next => $path_status->but(next => $check_dir)
64 my $res = $state->run;
65 is($res->scope_var('PS')->bound_value, $paths{'/home/me/.ssh'});
70 is($state->run, undef);
72 my $pop_stack = FromCode->new(code => sub { $_[1]->pop_return_stack });
74 my $ps_pop = $path_status->but(then => $pop_stack);
80 my ($self, $state) = @_;
81 my $path = $state->scope_var('P')->bound_value;
82 $state->return_from_run(
83 DX::ObservationRequired->new(
84 observer => sub { $paths{$path} = $observe_path{$path} },
85 resume => $state->then($self->next),
94 my ($self, $state) = @_;
95 my $var = DX::Var->new(id => 'OR')->with_stream(
96 ArrayStream->from_array(@path_status)
98 my $inner_or = FromCode->new(code => sub { $_[1]->then($var->bound_value) });
100 $state->push_return_then($self->next, $inner_or)
104 my $or_state = make_state([ 'P', 'PS' ],
106 next => FromCode->new(
113 my $ob_req = $or_state->run;
115 $ob_req->observer->();
118 my $res = $ob_req->resume->run;
119 is($res->scope_var('PS')->bound_value, $paths{'/home/me/.ssh'});