diff options
Diffstat (limited to 'lib/Data/MultiValued/Ranges.pm')
-rw-r--r-- | lib/Data/MultiValued/Ranges.pm | 162 |
1 files changed, 93 insertions, 69 deletions
diff --git a/lib/Data/MultiValued/Ranges.pm b/lib/Data/MultiValued/Ranges.pm index 7193df6..ef955ab 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_1'; +} +{ + $Data::MultiValued::Ranges::DIST = 'Data-MultiValued'; +} use Moose; use MooseX::Params::Validate; use Moose::Util::TypeConstraints; @@ -8,6 +14,83 @@ 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}; +} + + +1; + +__END__ +=pod + +=head1 NAME + +Data::MultiValued::Ranges - Handle values with validity ranges + +=head1 VERSION + +version 0.0.1_1 + =head1 SYNOPSIS use Data::MultiValued::Ranges; @@ -23,19 +106,6 @@ use Data::MultiValued::RangeContainer; =head1 METHODS -=cut - -has _storage => ( - is => 'rw', - isa => class_type('Data::MultiValued::RangeContainer'), - init_arg => undef, - lazy_build => 1, -); - -sub _build__storage { - Data::MultiValued::RangeContainer->new(); -} - =head2 C<set> $obj->set({ from => $min, to => $max, value => $the_value }); @@ -68,20 +138,6 @@ 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}; -} - =head2 C<get> my $value = $obj->get({ at => $point }); @@ -97,18 +153,6 @@ 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}; -} - =head2 C<clear> $obj->clear({ from => $min, to => $max }); @@ -135,18 +179,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,33 +188,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 + +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 -1; |