my @args = map $self->_expand_argspec($state, $_), @{$self->rule_args};
my @rules = @{$state->rule_set->rules->{$self->full_name}||[]};
die "No rules for ${\$self->full_name}" unless @rules;
- my $var = DX::Var->new(id => 'OR')
+ my $var = DX::Var->new(id => "rule:".$self->full_name)
->with_stream(DX::ArrayStream->from_array(@rules));
my $invoke = DX::Op::FromCode->new(
code => sub {
use DX::Op::MemberOf;
use DX::Op::ApplyConstraint;
use DX::Op::Return;
+use DX::Op::Cut;
use List::Util qw(reduce);
has rules => (is => 'ro', default => sub { {} });
DX::Op::CallRule->new(rule_name => $name, rule_args => \@args);
}
+sub _expand_cut { return DX::Op::Cut->new }
+
sub _expand_member_of {
my ($self, $member_var, $coll_var) = @_;
DX::Op::MemberOf->new(
my ($self) = @_;
my @stack = @{$self->return_stack};
my $top = pop @stack;
- $self->but(return_stack => \@stack, next_op => $top);
+ $self->but(return_stack => \@stack, next_op => $top->[0]);
}
sub push_return_then {
my ($self, $return, $then) = @_;
$self->but(
- return_stack => [ @{$self->return_stack}, $return ],
+ return_stack => [ @{$self->return_stack}, [ $return, $self ] ],
next_op => $then
);
}
use Test::More;
use DX::Solver;
use DX::SetOver;
+use Test::Exception;
{
package My::PathStatus;
) },
);
-my @rules = (
+$solver->add_rule(@$_) for (
[ path_status => [ qw(PS) ],
[ member_of => 'PS', [ value => 'path_status' ] ] ],
[ path => [ qw(PS P) ],
sub { $_[0]->info and $_[0]->info->is_file } ] ],
);
-$solver->add_rule(@$_) for @rules;
-
%path_status = %protos;
sub paths_for {
- join ' ', map $_->{PS}{path}, $solver->query(
- [ qw(PS) ], [ path_status => 'PS'], @_
+ join ' ', map $_->{PS}->path, $solver->query(
+ [ qw(PS) ], [ path_status => 'PS' ], @_
)->results;
}
is(paths_for([ is_file => 'PS' ]), '.ssh/authorized_keys');
is(paths_for([ mode => 'PS', [ value => '0755' ] ]), '.ssh');
+
+$solver->add_rule(
+ path_status_at => [ 'PS', 'P' ],
+ [ path_status => 'PS' ],
+ [ path => qw(PS P) ],
+);
+$solver->add_rule(
+ path_status_at => [ 'PS', 'P' ],
+ [ constrain => [] => sub { die "ARGH" } ]
+);
+
+throws_ok {
+ $solver->query(
+ [ qw(PS) ],
+ [ path_status_at => 'PS', [ value => '.ssh' ] ]
+ )->results
+} qr/ARGH/;
+
+delete $solver->rule_set->rules->{'path_status_at/2'};
+
+$solver->add_rule(
+ path_status_at => [ 'PS', 'P' ],
+ [ path_status => 'PS' ],
+ [ path => qw(PS P) ],
+ [ 'cut' ],
+);
+$solver->add_rule(
+ path_status_at => [ 'PS', 'P' ],
+ [ constrain => [] => sub { die "ARGH" } ]
+);
+
+my @res;
+
+lives_ok {
+ @res = $solver->query(
+ [ qw(PS) ],
+ [ path_status_at => 'PS', [ value => '.ssh' ] ]
+ )->results
+};
+
+is(join(' ', map $_->{PS}->path, @res), '.ssh');
+
+#::Dwarn($solver->query([ qw(PS) ], [ path_status_at => 'PS', [ value => '.ssh' ] ])->results);
+
+done_testing;