summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGianni Ceccarelli <dakkar@thenautilus.net>2011-11-10 18:01:33 +0000
committerGianni Ceccarelli <dakkar@thenautilus.net>2011-11-10 18:01:33 +0000
commit5cd777d053e604f209c064419ba3e39346315949 (patch)
tree8409f6a0cccc72bdae5b0dc9adea689104eab195
parentre-enable git plugins in dzil (diff)
downloaddata-multivalued-5cd777d053e604f209c064419ba3e39346315949.tar.gz
data-multivalued-5cd777d053e604f209c064419ba3e39346315949.tar.bz2
data-multivalued-5cd777d053e604f209c064419ba3e39346315949.zip
fix inserting range w/o overlap
-rw-r--r--lib/Data/MultiValued/RangeContainer.pm8
-rw-r--r--t/ranges-setting.t12
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/Data/MultiValued/RangeContainer.pm b/lib/Data/MultiValued/RangeContainer.pm
index 474626f..e9b1b62 100644
--- a/lib/Data/MultiValued/RangeContainer.pm
+++ b/lib/Data/MultiValued/RangeContainer.pm
@@ -154,13 +154,14 @@ sub _splice_slot {
# by costruction, the first and the last may have to be split, all
# others must be removed
- my $first_to_replace = $overlap->[0],
- my $last_to_replace = $overlap->[-1],
+ my $first_to_replace;
my $how_many = @$overlap;
my @replacement = $new ? ($new) : ();
if ($how_many > 0) { # we have to splice
+ $first_to_replace = $overlap->[0];
+ my $last_to_replace = $overlap->[-1];
my $first = $self->_storage->[$first_to_replace];
my $last = $self->_storage->[$last_to_replace];
@@ -181,6 +182,9 @@ sub _splice_slot {
}
}
}
+ else {
+ $first_to_replace = $before->[-1]+1;
+ }
splice @{$self->_storage},
$first_to_replace,$how_many,
diff --git a/t/ranges-setting.t b/t/ranges-setting.t
index b8d2a57..e8f4c77 100644
--- a/t/ranges-setting.t
+++ b/t/ranges-setting.t
@@ -24,6 +24,14 @@ sub test_it {
});
} 'setting 30-50';
+ lives_ok {
+ $obj->set({
+ from => 25,
+ to => 27,
+ value => [7,8,9],
+ });
+ } 'setting 30-50';
+
cmp_deeply($obj->get({at => 15}),
[1,2,3],
'getting 15');
@@ -50,6 +58,10 @@ sub test_it {
$obj->get({at => 50})
} 'getting 50 dies';
+ cmp_deeply($obj->get({at => 25}),
+ [7,8,9],
+ 'getting 25');
+
dies_ok {
$obj->get({at => 0})
} 'getting 0 dies';