From 5cd777d053e604f209c064419ba3e39346315949 Mon Sep 17 00:00:00 2001 From: Gianni Ceccarelli Date: Thu, 10 Nov 2011 18:01:33 +0000 Subject: fix inserting range w/o overlap --- lib/Data/MultiValued/RangeContainer.pm | 8 ++++++-- t/ranges-setting.t | 12 ++++++++++++ 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'; -- cgit v1.2.3