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.pm53
1 files changed, 37 insertions, 16 deletions
diff --git a/lib/Data/MultiValued/Ranges.pm b/lib/Data/MultiValued/Ranges.pm
index 21898af..7193df6 100644
--- a/lib/Data/MultiValued/Ranges.pm
+++ b/lib/Data/MultiValued/Ranges.pm
@@ -36,24 +36,12 @@ 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};
-}
-
=head2 C<set>
$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
@@ -90,7 +78,7 @@ sub set {
value => { isa => Any, },
);
- $self->_storage->set_or_create(\%args)
+ $self->_storage->get_or_create(\%args)
->{value} = $args{value};
}
@@ -125,7 +113,8 @@ sub get {
$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
@@ -158,6 +147,38 @@ sub clear {
$self->_storage->clear(\%args);
}
+=head1 Serialisation helpers
+
+These are used through
+L<Data::MultiValued::UglySerializationHelperRole>.
+
+=head2 C<_rebless_storage>
+
+Blesses the storage into L<Data::MultiValued::RangeContainer>.
+
+=cut
+
+sub _rebless_storage {
+ my ($self) = @_;
+
+ bless $self->{_storage},'Data::MultiValued::RangeContainer';
+}
+
+
+=head2 C<_as_hash>
+
+Returns the internal representation with no blessed hashes, with as
+few copies as possible.
+
+=cut
+
+sub _as_hash {
+ my ($self) = @_;
+
+ my %ret = %{$self->_storage};
+ return {_storage=>\%ret};
+}
+
=head1 SEE ALSO
L<Data::MultiValued::RangeContainer>, L<Data::MultiValued::Exceptions>