6 my $solver = DX::Solver->new;
10 has name => (is => 'ro', required => 1);
12 package My::ShellInstalled;
14 has server => (is => 'ro', required => 1);
15 has shell => (is => 'ro', required => 1);
18 $solver->facts->{server} = DX::OrderedSet->new(
19 values => [ map My::Server->new(name => $_), qw(one two three four five) ]
21 $solver->facts->{shell_installed} = DX::OrderedSet->new(
23 (map My::ShellInstalled->new(server => $_, shell => 'bash'),
25 (map My::ShellInstalled->new(server => $_, shell => 'csh'),
30 $solver->add_rule(has_shell => [ 'Srv', 'Shell' ],
31 [ member_of => 'SI', \'shell_installed' ],
32 [ prop => 'SI' => \'server' => 'Name' ],
33 [ prop => 'Srv' => \'name' => 'Name' ],
34 [ prop => 'SI' => \'shell' => 'Shell' ]
37 my @r = $solver->query(
38 [ findall => X => S =>
39 [ member_of => 'S', \'server' ],
40 [ has_shell => 'S', \'bash' ],
45 [ map $_->name, $r[0]->value_for('X')->all ],
46 [ qw(one three four) ]
50 [ foreach => S => [ [ member_of => 'S', \'server' ] ],
51 [ [ has_shell => 'S' => \'bash' ] ] ]
54 ok(!@r, 'No results for only bash');
56 $solver->add_rule(has_any_shell => [ 'S' ] => [ has_shell => 'S' => \'bash' ]);
57 $solver->add_rule(has_any_shell => [ 'S' ] => [ has_shell => 'S' => \'csh' ]);
60 [ foreach => S => [ [ member_of => 'S', \'server' ] ],
61 [ [ has_any_shell => 'S' ] ] ]
64 # only three matches both legs of has_any_shell
66 is(scalar(@r), 2, 'Two solutions for any shell');