diff options
author | Gianni Ceccarelli <dakkar@thenautilus.net> | 2011-11-14 14:48:16 +0000 |
---|---|---|
committer | Gianni Ceccarelli <dakkar@thenautilus.net> | 2011-11-14 14:48:16 +0000 |
commit | 5dbdfc53752cd050b171f416ea3625b18e4018b8 (patch) | |
tree | 1476217aa367a4cd1b10e22950c8dd8c503630d3 /lib/Data/MultiValued/Ranges.pm | |
parent | fix inserting range w/o overlap (diff) | |
download | data-multivalued-5dbdfc53752cd050b171f416ea3625b18e4018b8.tar.gz data-multivalued-5dbdfc53752cd050b171f416ea3625b18e4018b8.tar.bz2 data-multivalued-5dbdfc53752cd050b171f416ea3625b18e4018b8.zip |
some docs
Diffstat (limited to 'lib/Data/MultiValued/Ranges.pm')
-rw-r--r-- | lib/Data/MultiValued/Ranges.pm | 101 |
1 files changed, 100 insertions, 1 deletions
diff --git a/lib/Data/MultiValued/Ranges.pm b/lib/Data/MultiValued/Ranges.pm index 9c69626..21898af 100644 --- a/lib/Data/MultiValued/Ranges.pm +++ b/lib/Data/MultiValued/Ranges.pm @@ -6,7 +6,24 @@ use MooseX::Types::Moose qw(Num Str Undef Any); use Data::MultiValued::Exceptions; use Data::MultiValued::RangeContainer; -# ABSTRACT: Handle values with tags and validity ranges +# ABSTRACT: Handle values with validity ranges + +=head1 SYNOPSIS + + use Data::MultiValued::Ranges; + + my $obj = Data::MultiValued::Ranges->new(); + $obj->set({ + from => 10, + to => 20, + value => 'foo', + }); + say $obj->get({at => 15}); # prints 'foo' + say $obj->get({at => 35}); # dies + +=head1 METHODS + +=cut has _storage => ( is => 'rw', @@ -32,6 +49,39 @@ sub _as_hash { 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. + +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 ++Inf". Not passing in C<from> or C<to> is equivalent to passing +C<undef>. + +If the given range intersects existing ranges, these are spliced to +avoid overlaps. In other words: + + $obj->set({ + from => 10, + to => 20, + value => 'foo', + }); + $obj->set({ + from => 15, + to => 25, + value => 'bar', + }); + say $obj->get({at => 12}); # prints 'foo' + say $obj->get({at => 15}); # prints 'bar' + say $obj->get({at => 25}); # dies + +No cloning is done: if you pass in a reference, the reference is +just stored. + +=cut + sub set { my ($self,%args) = validated_hash( \@_, @@ -44,6 +94,23 @@ sub set { ->{value} = $args{value}; } +=head2 C<get> + + my $value = $obj->get({ at => $point }); + +Retrieves the value for the given point. Throws a +L<Data::MultiValued::Exceptions::RangeNotFound> exception if no ranges +exist in this object that include the point (remember that a range +does not include its C<to> point). + +A C<< at => undef >> means "at -Inf". Not passing in C<at> is +equivalent to passing C<undef>. + +No cloning is done: if a reference was stored, you get it back +untouched. + +=cut + sub get { my ($self,%args) = validated_hash( \@_, @@ -54,6 +121,33 @@ sub get { ->{value}; } +=head2 C<clear> + + $obj->clear({ from => $min, to => $max }); + +Deletes all values for the given range. Does not throw exceptions. + +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 +passing C<undef>. Thus, C<< $obj->clear() >> clears everything. + +If the given range intersects existing ranges, these are spliced. In +other words: + + $obj->set({ + from => 10, + to => 20, + value => 'foo', + }); + $obj->clear({ + from => 15, + to => 25, + }); + say $obj->get({at => 12}); # prints 'foo' + say $obj->get({at => 15}); # dies + +=cut + sub clear { my ($self,%args) = validated_hash( \@_, @@ -64,5 +158,10 @@ sub clear { $self->_storage->clear(\%args); } +=head1 SEE ALSO + +L<Data::MultiValued::RangeContainer>, L<Data::MultiValued::Exceptions> + +=cut 1; |