3 use aliased 'DX::Op::FromCode';
4 use aliased 'DX::ArrayStream';
8 use DX::ObservationRequired;
11 '/home/me/.ssh' => { is_directory => 1 },
12 '/home/me/.ssh/authorized_keys' => { is_file => 1 },
14 my %paths = %observe_path;
16 my $set_dot_ssh = FromCode->new(
18 my ($self, $state) = @_;
19 $state->bind_var_then($state->scope_var('P'), '/home/me/.ssh', $self->next);
23 my $path_status = FromCode->new(
25 my ($self, $state) = @_;
26 if (my $p = $paths{$state->scope_var('P')->bound_value}) {
27 return $state->bind_var_then($state->scope_var('PS'), $p, $self->next);
29 return $state->backtrack;
33 my $check_dir = FromCode->new(
35 my ($self, $state) = @_;
36 if ($state->scope_var('PS')->bound_value->{is_directory}) {
37 return $state->then($self->next);
39 return $state->backtrack;
46 my %scope = map +($_ => $_), @{$vars};
47 my %by_id = map +($_ => DX::Var->new(id => $_)), @{$vars};
58 my $state = make_state([ 'P', 'PS' ],
60 next => $path_status->but(next => $check_dir)
65 my $res = $state->run;
66 is($res->scope_var('PS')->bound_value, $paths{'/home/me/.ssh'});
71 is($state->run, undef);
73 my $pop_stack = FromCode->new(code => sub { $_[1]->pop_return_stack });
75 my $ps_pop = $path_status->but(then => $pop_stack);
81 my ($self, $state) = @_;
82 my $path = $state->scope_var('P')->bound_value;
83 $state->return_from_run(
84 DX::ObservationRequired->new(
85 observation => sub { $paths{$path} = $observe_path{$path} },
86 resume => $state->then($self->next),
95 my ($self, $state) = @_;
96 my $var = DX::Var->new(id => 'OR')->with_stream(
97 ArrayStream->from_array(@path_status)
99 my $inner_or = FromCode->new(code => sub { $_[1]->then($var->bound_value) });
101 $state->push_return_then($self->next, $inner_or)
105 my $or_state = make_state([ 'P', 'PS' ],
107 next => FromCode->new(
114 my $ob_req = $or_state->run;
116 $ob_req->observation->();
119 my $res = $ob_req->resume->run;
120 is($res->scope_var('PS')->bound_value, $paths{'/home/me/.ssh'});