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_value($state->scope_var('P')->id, '/home/me/.ssh')
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_value($state->scope_var('PS')->id, $p)
30 return $state->backtrack;
34 my $check_dir = FromCode->new(
36 my ($self, $state) = @_;
37 if ($state->scope_var('PS')->bound_value->{is_directory}) {
38 return $state->then($self->next);
40 return $state->backtrack;
47 my %scope = map +($_ => $_), @{$vars};
48 my %by_id = map +($_ => DX::Var->new(id => $_)), @{$vars};
59 my $state = make_state([ 'P', 'PS' ],
61 next => $path_status->but(next => $check_dir)
66 my $res = $state->run;
67 is($res->scope_var('PS')->bound_value, $paths{'/home/me/.ssh'});
72 is($state->run, undef);
74 my $pop_stack = FromCode->new(code => sub { $_[1]->pop_return_stack });
76 my $ps_pop = $path_status->but(then => $pop_stack);
82 my ($self, $state) = @_;
83 my $path = $state->scope_var('P')->bound_value;
84 $state->return_from_run(
85 DX::ObservationRequired->new(
86 observer => sub { $paths{$path} = $observe_path{$path} },
87 resume => $state->then($self->next),
96 my ($self, $state) = @_;
97 my $var = DX::Var->new(id => 'OR')->with_stream(
98 ArrayStream->from_array(@path_status)
100 my $inner_or = FromCode->new(code => sub { $_[1]->then($var->bound_value) });
102 $state->push_return_then($self->next, $inner_or)
106 my $or_state = make_state([ 'P', 'PS' ],
108 next => FromCode->new(
115 my $ob_req = $or_state->run;
117 $ob_req->observer->();
120 my $res = $ob_req->resume->run;
121 is($res->scope_var('PS')->bound_value, $paths{'/home/me/.ssh'});