summaryrefslogtreecommitdiff
path: root/lib/Data/MultiValued/TagsAndRanges.pm
blob: cc57b165d63ad64bdee7f88c657bbaa67e65a994 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package Data::MultiValued::TagsAndRanges; 
BEGIN {
  $Data::MultiValued::TagsAndRanges::VERSION = '0.0.1';
}
BEGIN {
  $Data::MultiValued::TagsAndRanges::DIST = 'Data-MultiValued';
}
use Moose;
use MooseX::Params::Validate;
use Moose::Util::TypeConstraints;
use MooseX::Types::Moose qw(Num Str Undef Any);
use Data::MultiValued::Exceptions;
use Data::MultiValued::TagContainerForRanges;
 
# ABSTRACT: Handle values with tags and validity ranges 
 
has _storage => (
    is => 'rw',
    isa => class_type('Data::MultiValued::TagContainerForRanges'),
    init_arg => undef,
    lazy_build => 1,
);
 
sub _build__storage {
    Data::MultiValued::TagContainerForRanges->new();
}
 
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};
}
 
sub set {
    my ($self,%args) = validated_hash(
        \@_,
        from => { isa => Num|Undef, optional => 1, },
        to => { isa => Num|Undef, optional => 1, },
        tag => { isa => Str, optional => 1, },
        value => { isa => Any, },
    );
 
    $self->_storage->get_or_create(\%args)
         ->set_or_create(\%args)
         ->{value} = $args{value};
}
 
sub get {
    my ($self,%args) = validated_hash(
        \@_,
        at => { isa => Num|Undef, optional => 1, },
        tag => { isa => Str, optional => 1, },
    );
 
    $self->_storage->get(\%args)
         ->get(\%args)
         ->{value};
}
 
sub clear {
    my ($self,%args) = validated_hash(
        \@_,
        from => { isa => Num|Undef, optional => 1, },
        to => { isa => Num|Undef, optional => 1, },
        tag => { isa => Str, optional => 1, },
    );
 
    if (exists $args{from} || exists $args{to}) {
        $self->_storage->get(\%args)
            ->clear(\%args);
    }
    else {
        $self->_storage->clear(\%args);
    }
}
 
1;
 
__END__
=pod
 
=head1 NAME
 
Data::MultiValued::TagsAndRanges - Handle values with tags and validity ranges
 
=head1 VERSION
 
version 0.0.1
 
=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