summaryrefslogtreecommitdiff
path: root/lib/Data/MultiValued/TagsAndRanges.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/MultiValued/TagsAndRanges.pm')
-rw-r--r--lib/Data/MultiValued/TagsAndRanges.pm173
1 files changed, 101 insertions, 72 deletions
diff --git a/lib/Data/MultiValued/TagsAndRanges.pm b/lib/Data/MultiValued/TagsAndRanges.pm
index 43bff6b..e75f0f5 100644
--- a/lib/Data/MultiValued/TagsAndRanges.pm
+++ b/lib/Data/MultiValued/TagsAndRanges.pm
@@ -1,4 +1,10 @@
package Data::MultiValued::TagsAndRanges;
+{
+ $Data::MultiValued::TagsAndRanges::VERSION = '0.0.1_5';
+}
+{
+ $Data::MultiValued::TagsAndRanges::DIST = 'Data-MultiValued';
+}
use Moose;
use namespace::autoclean;
use MooseX::Params::Validate;
@@ -8,22 +14,6 @@ use Data::MultiValued::TagContainerForRanges;
# ABSTRACT: Handle values with tags and validity ranges
-=head1 SYNOPSIS
-
- use Data::MultiValued::TagsAndRanges;
-
- my $obj = Data::MultiValued::TagsAndRanges->new();
- $obj->set({
- tag => 'tag1',
- from => 10,
- to => 20,
- value => 'foo',
- });
- say $obj->get({tag => 'tag1', at => 15}); # prints 'foo'
- say $obj->get({tag => 'tag1', at => 35}); # dies
- say $obj->get({tag => 'tag2', at => 15}); # dies
-
-=cut
has _storage => (
is => 'rw',
@@ -36,17 +26,6 @@ sub _build__storage {
Data::MultiValued::TagContainerForRanges->new();
}
-=method C<set>
-
- $obj->set({ tag => $the_tag, from => $min, to => $max, value => $the_value });
-
-Stores the given value for the given tag and range. Does not throw
-exceptions.
-
-See L<Data::MultiValued::Tags/set> and
-L<Data::MultiValued::Ranges/set> for more details.
-
-=cut
sub set {
my ($self,%args) = validated_hash(
@@ -62,21 +41,6 @@ sub set {
->{value} = $args{value};
}
-=method C<get>
-
- my $value = $obj->get({ tag => $the_tag, at => $point });
-
-Retrieves the value for the given tag and point. Throws a
-L<Data::MultiValued::Exceptions::RangeNotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::RangeNotFound>
-exception if no ranges exist in this object that include the point,
-and
-L<Data::MultiValued::Exceptions::TagNotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::TagNotFound>
-exception if the tag does not exists in this object.
-
-See L<Data::MultiValued::Tags/get> and
-L<Data::MultiValued::Ranges/get> for more details.
-
-=cut
sub get {
my ($self,%args) = validated_hash(
@@ -90,19 +54,6 @@ sub get {
->{value};
}
-=method C<clear>
-
- $obj->clear({ tag => $the_tag, from => $min, to => $max });
-
-If a range is specified, deletes all values for the given range and
-tag. If no range is specified, delete all values for the given tag.
-
-Does not throw exceptions.
-
-See L<Data::MultiValued::Tags/clear> and
-L<Data::MultiValued::Ranges/clear> for more details.
-
-=cut
sub clear {
my ($self,%args) = validated_hash(
@@ -121,6 +72,92 @@ sub clear {
}
}
+
+sub _rebless_storage {
+ my ($self) = @_;
+
+ bless $self->{_storage},'Data::MultiValued::TagContainerForRanges';
+ $self->_storage->_rebless_storage;
+}
+
+
+sub _as_hash {
+ my ($self) = @_;
+
+ my $ret = $self->_storage->_as_hash;
+ return {_storage=>$ret};
+}
+
+__PACKAGE__->meta->make_immutable();
+
+1;
+
+__END__
+=pod
+
+=encoding utf-8
+
+=head1 NAME
+
+Data::MultiValued::TagsAndRanges - Handle values with tags and validity ranges
+
+=head1 VERSION
+
+version 0.0.1_5
+
+=head1 SYNOPSIS
+
+ use Data::MultiValued::TagsAndRanges;
+
+ my $obj = Data::MultiValued::TagsAndRanges->new();
+ $obj->set({
+ tag => 'tag1',
+ from => 10,
+ to => 20,
+ value => 'foo',
+ });
+ say $obj->get({tag => 'tag1', at => 15}); # prints 'foo'
+ say $obj->get({tag => 'tag1', at => 35}); # dies
+ say $obj->get({tag => 'tag2', at => 15}); # dies
+
+=head1 METHODS
+
+=head2 C<set>
+
+ $obj->set({ tag => $the_tag, from => $min, to => $max, value => $the_value });
+
+Stores the given value for the given tag and range. Does not throw
+exceptions.
+
+See L<Data::MultiValued::Tags/set> and
+L<Data::MultiValued::Ranges/set> for more details.
+
+=head2 C<get>
+
+ my $value = $obj->get({ tag => $the_tag, at => $point });
+
+Retrieves the value for the given tag and point. Throws a
+L<Data::MultiValued::Exceptions::RangeNotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::RangeNotFound>
+exception if no ranges exist in this object that include the point,
+and
+L<Data::MultiValued::Exceptions::TagNotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::TagNotFound>
+exception if the tag does not exists in this object.
+
+See L<Data::MultiValued::Tags/get> and
+L<Data::MultiValued::Ranges/get> for more details.
+
+=head2 C<clear>
+
+ $obj->clear({ tag => $the_tag, from => $min, to => $max });
+
+If a range is specified, deletes all values for the given range and
+tag. If no range is specified, delete all values for the given tag.
+
+Does not throw exceptions.
+
+See L<Data::MultiValued::Tags/clear> and
+L<Data::MultiValued::Ranges/clear> for more details.
+
=head1 Serialisation helpers
These are used through
@@ -131,30 +168,22 @@ L<Data::MultiValued::UglySerializationHelperRole>.
Blesses the storage into L<Data::MultiValued::TagContainerForRanges>,
then calls C<_rebless_storage> on it.
-=cut
-
-sub _rebless_storage {
- my ($self) = @_;
-
- bless $self->{_storage},'Data::MultiValued::TagContainerForRanges';
- $self->_storage->_rebless_storage;
-}
-
=head2 C<_as_hash>
Returns the internal representation with no blessed hashes, with as
few copies as possible. Depends on
L<Data::MultiValued::TagContainerForRanges/_as_hash>.
-=cut
+=head1 AUTHOR
-sub _as_hash {
- my ($self) = @_;
+Gianni Ceccarelli <dakkar@thenautilus.net>
- my $ret = $self->_storage->_as_hash;
- return {_storage=>$ret};
-}
+=head1 COPYRIGHT AND LICENSE
-__PACKAGE__->meta->make_immutable();
+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;