=head1 VERSION
-Version 0.01
+Version 0.02
=cut
-our $VERSION = '0.01';
+our $VERSION = '0.02';
=head1 DESCRIPTION
If C<$replace> is true, then the rule will replace the first rule in the list that is a subclass or that consumes the role denoted by the target.
All the subsequent rules in the list that inherit or consume the target will be removed.
+Returns true if and only if an existent rule was replaced.
+
=cut
sub insert {
my $overwrite = $args{overwrite};
my $replace = $args{replace};
- my $target = $rule->target;
- 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;
}
}
}
- my $shift;
+ my $shift = 0;
for (@remove) {
splice @$list, $_ - $shift, 1;
++$shift;
}
- return 1 unless defined $rule;
+ return 1 if $replaced;
} else { # Replace only an existent rule
+ my $target = $rule->target;
for my $i (0 .. $#$list) {
my $old_target = $list->[$i]->target;