}
sub allocate_var {
- my ($self, $name, $var) = @_;
- my $id = join('_', $name, ++($self->id_gen->{$name}));
+ my ($self, $name, $var, $id_gen) = @_;
+ my $id = join('_', $name, ++($id_gen->{$name}||='000'));
DX::Var->new(id => $id, %$var);
}
-sub assign_vars {
+sub expand_vars {
my ($self, %vars) = @_;
my %by_id = %{$self->by_id};
- my $state = $self->but(id_gen => { %{$self->id_gen} });
+ my %id_gen = %{$self->id_gen};
foreach my $name (keys %vars) {
unless (blessed($vars{$name})) {
- my $var = $vars{$name} = $state->allocate_var($name, $vars{$name});
+ my $var = $vars{$name} = $self->allocate_var(
+ $name, $vars{$name}, \%id_gen
+ );
$by_id{$var->id} = $var;
}
}
+ $self->but(
+ by_id => \%by_id, id_gen => \%id_gen,
+ ), %vars;
+}
+
+sub assign_vars {
+ my ($self, %vars) = @_;
+ my ($state, %expanded) = $self->expand_vars(%vars);
$state->but(
- by_id => \%by_id,
- scope => { %{$self->scope}, map +($_ => $vars{$_}->id), keys %vars }
+ scope => { %{$self->scope}, map +($_ => $expanded{$_}->id), keys %expanded }
);
}