summaryrefslogtreecommitdiff
path: root/lib/Data/MultiValued/Ranges.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/MultiValued/Ranges.pm')
-rw-r--r--lib/Data/MultiValued/Ranges.pm51
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>