diff options
author | Gianni Ceccarelli <dakkar@thenautilus.net> | 2011-11-14 15:52:15 +0000 |
---|---|---|
committer | Gianni Ceccarelli <dakkar@thenautilus.net> | 2011-11-14 15:52:15 +0000 |
commit | 7ea924794a0006284760a33498832ff2c3e15223 (patch) | |
tree | ee3ad341c3cf47c3a7922b075d69f1e269cd5d20 /lib/Data/MultiValued/Ranges.pm | |
parent | Build results of dd15e2e (on master) (diff) | |
parent | more docs (diff) | |
download | data-multivalued-7ea924794a0006284760a33498832ff2c3e15223.tar.gz data-multivalued-7ea924794a0006284760a33498832ff2c3e15223.tar.bz2 data-multivalued-7ea924794a0006284760a33498832ff2c3e15223.zip |
Build results of 831f847 (on master)
Diffstat (limited to 'lib/Data/MultiValued/Ranges.pm')
-rw-r--r-- | lib/Data/MultiValued/Ranges.pm | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/lib/Data/MultiValued/Ranges.pm b/lib/Data/MultiValued/Ranges.pm index 296ae76..6ea55c1 100644 --- a/lib/Data/MultiValued/Ranges.pm +++ b/lib/Data/MultiValued/Ranges.pm @@ -26,19 +26,6 @@ sub _build__storage { Data::MultiValued::RangeContainer->new(); } -sub _rebless_storage { - my ($self) = @_; - - bless $self->{_storage},'Data::MultiValued::RangeContainer'; -} - -sub _as_hash { - my ($self) = @_; - - my %ret = %{$self->_storage}; - return {_storage=>\%ret}; -} - sub set { my ($self,%args) = validated_hash( @@ -48,7 +35,7 @@ sub set { value => { isa => Any, }, ); - $self->_storage->set_or_create(\%args) + $self->_storage->get_or_create(\%args) ->{value} = $args{value}; } @@ -75,6 +62,22 @@ sub clear { } +sub _rebless_storage { + my ($self) = @_; + + bless $self->{_storage},'Data::MultiValued::RangeContainer'; +} + + + +sub _as_hash { + my ($self) = @_; + + my %ret = %{$self->_storage}; + return {_storage=>\%ret}; +} + + 1; __END__ @@ -107,7 +110,8 @@ version 0.0.1 $obj->set({ from => $min, to => $max, value => $the_value }); -Stores the given value for the given range. Does not throw exceptions. +Stores the given value for the given range. Throws +L<Data::MultiValued::Exceptions::BadRange> if C<< $min > $max >>. The range is defined as C<< Num $x : $min <= $x < $max >>. A C<< from => undef >> means "from -Inf", and a C<< to => undef >> means "to @@ -153,7 +157,8 @@ untouched. $obj->clear({ from => $min, to => $max }); -Deletes all values for the given range. Does not throw exceptions. +Deletes all values for the given range. Throws +L<Data::MultiValued::Exceptions::BadRange> if C<< $min > $max >>. A C<< from => undef >> means "from -Inf", and a C<< to => undef >> means "to +Inf". Not passing in C<from> or C<to> is equivalent to @@ -174,6 +179,20 @@ other words: say $obj->get({at => 12}); # prints 'foo' say $obj->get({at => 15}); # dies +=head1 Serialisation helpers + +These are used through +L<Data::MultiValued::UglySerializationHelperRole>. + +=head2 C<_rebless_storage> + +Blesses the storage into L<Data::MultiValued::RangeContainer>. + +=head2 C<_as_hash> + +Returns the internal representation with no blessed hashes, with as +few copies as possible. + =head1 SEE ALSO L<Data::MultiValued::RangeContainer>, L<Data::MultiValued::Exceptions> |