my $is_role = $rule->is_role;
if ($replace) {
- my @remove;
+ my (@remove, $replaced);
for my $i (0 .. $#$list) {
my $old_target = $list->[$i]->target;
if ($rule->handles($old_target)) {
- if (defined $rule) {
- splice @$list, $i, 1, $rule;
- $rule = undef;
- } else {
+ if ($replaced) {
push @remove, $i;
+ } else {
+ splice @$list, $i, 1, $rule;
+ $replaced = 1;
}
}
}
splice @$list, $_ - $shift, 1;
++$shift;
}
- return 1 unless defined $rule;
+ return 1 if $replaced;
} else { # Replace only an existent rule