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.pm174
1 files changed, 101 insertions, 73 deletions
diff --git a/lib/Data/MultiValued/Ranges.pm b/lib/Data/MultiValued/Ranges.pm
index d03153d..9beb1a8 100644
--- a/lib/Data/MultiValued/Ranges.pm
+++ b/lib/Data/MultiValued/Ranges.pm
@@ -1,4 +1,10 @@
package Data::MultiValued::Ranges;
+{
+ $Data::MultiValued::Ranges::VERSION = '0.0.1_5';
+}
+{
+ $Data::MultiValued::Ranges::DIST = 'Data-MultiValued';
+}
use Moose;
use namespace::autoclean;
use Moose::Util::TypeConstraints;
@@ -8,6 +14,87 @@ use Data::MultiValued::RangeContainer;
# ABSTRACT: Handle values with validity ranges
+
+has _storage => (
+ is => 'rw',
+ isa => class_type('Data::MultiValued::RangeContainer'),
+ init_arg => undef,
+ lazy_build => 1,
+);
+
+sub _build__storage {
+ Data::MultiValued::RangeContainer->new();
+}
+
+
+sub set {
+ my ($self,%args) = validated_hash(
+ \@_,
+ from => { isa => 'Num|Undef', optional => 1, },
+ to => { isa => 'Num|Undef', optional => 1, },
+ value => { isa => 'Any', },
+ );
+
+ $self->_storage->get_or_create(\%args)
+ ->{value} = $args{value};
+}
+
+
+sub get {
+ my ($self,%args) = validated_hash(
+ \@_,
+ at => { isa => 'Num|Undef', optional => 1, },
+ );
+
+ $self->_storage->get(\%args)
+ ->{value};
+}
+
+
+sub clear {
+ my ($self,%args) = validated_hash(
+ \@_,
+ from => { isa => 'Num|Undef', optional => 1, },
+ to => { isa => 'Num|Undef', optional => 1, },
+ );
+
+ $self->_storage->clear(\%args);
+}
+
+
+sub _rebless_storage {
+ my ($self) = @_;
+
+ bless $self->{_storage},'Data::MultiValued::RangeContainer';
+}
+
+
+
+sub _as_hash {
+ my ($self) = @_;
+
+ my %ret = %{$self->_storage};
+ return {_storage=>\%ret};
+}
+
+
+__PACKAGE__->meta->make_immutable();
+
+1;
+
+__END__
+=pod
+
+=encoding utf-8
+
+=head1 NAME
+
+Data::MultiValued::Ranges - Handle values with validity ranges
+
+=head1 VERSION
+
+version 0.0.1_5
+
=head1 SYNOPSIS
use Data::MultiValued::Ranges;
@@ -21,20 +108,9 @@ use Data::MultiValued::RangeContainer;
say $obj->get({at => 15}); # prints 'foo'
say $obj->get({at => 35}); # dies
-=cut
+=head1 METHODS
-has _storage => (
- is => 'rw',
- isa => class_type('Data::MultiValued::RangeContainer'),
- init_arg => undef,
- lazy_build => 1,
-);
-
-sub _build__storage {
- Data::MultiValued::RangeContainer->new();
-}
-
-=method C<set>
+=head2 C<set>
$obj->set({ from => $min, to => $max, value => $the_value });
@@ -67,21 +143,7 @@ avoid overlaps. In other words:
No cloning is done: if you pass in a reference, the reference is
just stored.
-=cut
-
-sub set {
- my ($self,%args) = validated_hash(
- \@_,
- from => { isa => 'Num|Undef', optional => 1, },
- to => { isa => 'Num|Undef', optional => 1, },
- value => { isa => 'Any', },
- );
-
- $self->_storage->get_or_create(\%args)
- ->{value} = $args{value};
-}
-
-=method C<get>
+=head2 C<get>
my $value = $obj->get({ at => $point });
@@ -96,19 +158,7 @@ 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(
- \@_,
- at => { isa => 'Num|Undef', optional => 1, },
- );
-
- $self->_storage->get(\%args)
- ->{value};
-}
-
-=method C<clear>
+=head2 C<clear>
$obj->clear({ from => $min, to => $max });
@@ -135,18 +185,6 @@ other words:
say $obj->get({at => 12}); # prints 'foo'
say $obj->get({at => 15}); # dies
-=cut
-
-sub clear {
- my ($self,%args) = validated_hash(
- \@_,
- from => { isa => 'Num|Undef', optional => 1, },
- to => { isa => 'Num|Undef', optional => 1, },
- );
-
- $self->_storage->clear(\%args);
-}
-
=head1 Serialisation helpers
These are used through
@@ -156,35 +194,25 @@ L<Data::MultiValued::UglySerializationHelperRole>.
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
+=head1 SEE ALSO
-sub _as_hash {
- my ($self) = @_;
+L<Data::MultiValued::RangeContainer>, L<Data::MultiValued::Exceptions>
- my %ret = %{$self->_storage};
- return {_storage=>\%ret};
-}
+=head1 AUTHOR
-=head1 SEE ALSO
+Gianni Ceccarelli <dakkar@thenautilus.net>
-L<Data::MultiValued::RangeContainer>, L<Data::MultiValued::Exceptions>
+=head1 COPYRIGHT AND LICENSE
-=cut
+This software is copyright (c) 2011 by Net-a-Porter.com.
-__PACKAGE__->meta->make_immutable();
+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
-1;