sub run {
my ($self, $state) = @_;
#warn "Call: ".$self->full_name;
- my @args = map $self->_expand_argspec($state, $_), @{$self->rule_args};
+ my @args;
+ foreach my $arg (@{$self->rule_args}) {
+ ($state, my $expanded) = $self->_expand_argspec($state, $arg);
+ push @args, $expanded;
+ }
my @rules = @{$state->rule_set->rules->{$self->full_name}||[]};
die "No rules for ${\$self->full_name}" unless @rules;
my $var = DX::Var->new(id => "rule:".$self->full_name)
sub _expand_args {
my ($self, $state, %spec) = @_;
my %args;
- @args{keys %spec} = map $self->_expand_argspec($state, $_), values %spec;
+ foreach my $key (keys %spec) {
+ ($state, $args{$key}) = $self->_expand_argspec($state, $spec{$key});
+ }
return $state->expand_vars(%args);
}
sub _expand_argspec {
my ($self, $state, $spec) = @_;
if (!ref($spec)) {
- $state->scope_var($spec)
+ ($state->has_scope_var($spec)
+ ? ($state, $state->scope_var($spec))
+ : (map { $_, $_->scope_var($spec) } $state->assign_vars($spec => {})));
} elsif (ref($spec) eq 'ARRAY') {
if ($spec->[0] eq 'value') {
- +{ bound_value => $spec->[1] };
+ ($state, +{ bound_value => $spec->[1] });
} else {
die "Arrayref in argspec is not value";
}
} elsif (ref($spec) eq 'SCALAR' or ref($spec) eq 'REF') {
- return +{ bound_value => $$spec };
+ return ($state, +{ bound_value => $$spec });
} else {
die "Argspec incomprehensible";
}
has actions => (is => 'ro', default => sub { {} });
+sub has_scope_var {
+ my ($self, $name) = @_;
+ return !!$self->scope->{$name};
+}
+
sub scope_var {
my ($self, $name) = @_;
my $id = $self->scope->{$name}
[ path => [ qw(PS P) ],
[ prop => 'PS', \'path', 'P' ] ],
[ info_prop => [ qw(PS N V) ],
- [ exists => [ qw(PSI) ],
- [ prop => 'PS', \'info', 'PSI' ],
- [ prop => 'PSI', 'N', 'V' ] ] ],
+ [ prop => 'PS', \'info', 'PSI' ],
+ [ prop => 'PSI', 'N', 'V' ] ],
[ mode => [ qw(PS M) ],
[ info_prop => 'PS', \'mode', 'M' ] ],
[ exists_path => [ qw(PS) ],
$solver->add_rule(@$_) for (
[ file_in => [ qw(DirStatus FileName FileStatus) ],
[ is_directory => qw(DirStatus) ],
- [ exists => [ qw(DirPath) ],
- [ path => qw(DirStatus DirPath) ],
- [ exists => [ qw(FilePath) ],
- [ catfile => qw(DirPath FileName FilePath) ],
- [ file_at => qw(FileStatus FilePath) ] ] ] ],
+ [ path => qw(DirStatus DirPath) ],
+ [ catfile => qw(DirPath FileName FilePath) ],
+ [ file_at => qw(FileStatus FilePath) ] ],
[ is_file => [ qw(PS) ],
[ not => [ exists_path => 'PS' ] ],
[ act => [ 'PS' ],