diff options
Diffstat (limited to 'lib/Data/MultiValued/RangeContainer.pm')
-rw-r--r-- | lib/Data/MultiValued/RangeContainer.pm | 146 |
1 files changed, 88 insertions, 58 deletions
diff --git a/lib/Data/MultiValued/RangeContainer.pm b/lib/Data/MultiValued/RangeContainer.pm index 53b6c4c..293c58b 100644 --- a/lib/Data/MultiValued/RangeContainer.pm +++ b/lib/Data/MultiValued/RangeContainer.pm @@ -1,4 +1,10 @@ package Data::MultiValued::RangeContainer; +{ + $Data::MultiValued::RangeContainer::VERSION = '0.0.3'; +} +{ + $Data::MultiValued::RangeContainer::DIST = 'Data-MultiValued'; +} use Moose; use namespace::autoclean; use Moose::Util::TypeConstraints; @@ -8,22 +14,6 @@ use Data::MultiValued::Exceptions; # ABSTRACT: container for ranged values -=head1 DESCRIPTION - -Please don't use this module directly, use L<Data::MultiValued::Ranges>. - -This module implements the storage for ranged data. It's similar to -L<Array::IntSpan>, but simpler (and slower). - -A range is defined by a pair of numbers, C<from> and C<to>, and it -contains C<< Num $x : $min <= $x < $max >>. C<undef> is treated as -"inf" (negative infinity if used as C<from> or C<at>, positive -infinity if used as C<to>). - -The internal representation of a range is a hash with three keys, -C<from> C<to> C<value>. - -=cut has _storage => ( is => 'rw', @@ -38,15 +28,6 @@ has _storage => ( default => sub { [ ] }, ); -=method C<get> - - my $value = $obj->get({ at => $point }); - -Retrieves the range that includes the given point. Throws a -L<Data::MultiValued::Exceptions::RangeNotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::RangeNotFound> -exception if no range includes the point. - -=cut sub get { my ($self,$args) = @_; @@ -116,17 +97,6 @@ sub _partition_slots { return \@before,\@overlap,\@after; } -=method C<get_or_create> - - $obj->get_or_create({ from => $min, to => $max }); - -Retrieves the range that has the given extremes. If no such range -exists, creates a new range, splicing any existing overlapping range, -and returns it. Throws -L<Data::MultiValued::Exceptions::BadRange|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::BadRange> -if C<< $min > $max >>. - -=cut sub get_or_create { my ($self,$args) = @_; @@ -151,20 +121,6 @@ sub get_or_create { return $range; } -=method C<clear> - - $obj->clear({ from => $min, to => $max }); - -Removes the range that has the given extremes. If no such range -exists, splices any existing overlapping range so that C<< -$obj->get({at => $point }) >> for any C<< $min <= $point < $max >> -will die. - -Throws -L<Data::MultiValued::Exceptions::BadRange|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::BadRange> -if C<< $min > $max >>. - -=cut sub clear { my ($self,$args) = @_; @@ -270,14 +226,6 @@ sub _splice_slot { return $new; } -=method C<all_ranges> - - my @ranges = $obj->all_ranges; - -Returns all the ranges defined in this object, as a list of 2-elements -arrayrefs. - -=cut sub all_ranges { my ($self) = @_; @@ -288,3 +236,85 @@ sub all_ranges { __PACKAGE__->meta->make_immutable(); 1; + +__END__ +=pod + +=encoding utf-8 + +=head1 NAME + +Data::MultiValued::RangeContainer - container for ranged values + +=head1 VERSION + +version 0.0.3 + +=head1 DESCRIPTION + +Please don't use this module directly, use L<Data::MultiValued::Ranges>. + +This module implements the storage for ranged data. It's similar to +L<Array::IntSpan>, but simpler (and slower). + +A range is defined by a pair of numbers, C<from> and C<to>, and it +contains C<< Num $x : $min <= $x < $max >>. C<undef> is treated as +"inf" (negative infinity if used as C<from> or C<at>, positive +infinity if used as C<to>). + +The internal representation of a range is a hash with three keys, +C<from> C<to> C<value>. + +=head1 METHODS + +=head2 C<get> + + my $value = $obj->get({ at => $point }); + +Retrieves the range that includes the given point. Throws a +L<Data::MultiValued::Exceptions::RangeNotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::RangeNotFound> +exception if no range includes the point. + +=head2 C<get_or_create> + + $obj->get_or_create({ from => $min, to => $max }); + +Retrieves the range that has the given extremes. If no such range +exists, creates a new range, splicing any existing overlapping range, +and returns it. Throws +L<Data::MultiValued::Exceptions::BadRange|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::BadRange> +if C<< $min > $max >>. + +=head2 C<clear> + + $obj->clear({ from => $min, to => $max }); + +Removes the range that has the given extremes. If no such range +exists, splices any existing overlapping range so that C<< +$obj->get({at => $point }) >> for any C<< $min <= $point < $max >> +will die. + +Throws +L<Data::MultiValued::Exceptions::BadRange|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::BadRange> +if C<< $min > $max >>. + +=head2 C<all_ranges> + + my @ranges = $obj->all_ranges; + +Returns all the ranges defined in this object, as a list of 2-elements +arrayrefs. + +=head1 AUTHOR + +Gianni Ceccarelli <dakkar@thenautilus.net> + +=head1 COPYRIGHT AND LICENSE + +This software is copyright (c) 2011 by Net-a-Porter.com. + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +=cut + |