X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FLaTeX%2FTikZ%2FFunctor%2FRule.pm;h=bccbb48d739707e5a5f416d4356c98533596416d;hb=e82708f9111395800d13087a846bbec8a76cfcca;hp=15cc4899600a2b58491fe7db5cbe8f07250fff4d;hpb=2f8d25c7ced8c8bc43802025240ab7d673892f5d;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/lib/LaTeX/TikZ/Functor/Rule.pm b/lib/LaTeX/TikZ/Functor/Rule.pm index 15cc489..bccbb48 100644 --- a/lib/LaTeX/TikZ/Functor/Rule.pm +++ b/lib/LaTeX/TikZ/Functor/Rule.pm @@ -9,11 +9,11 @@ LaTeX::TikZ::Functor::Rule - An object that specifies how functors should handle =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; =head1 DESCRIPTION @@ -129,6 +129,8 @@ If C<$replace> is false, then the rule will be appended to the C<@list> ; except 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 { @@ -140,32 +142,30 @@ 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;