package Data::MultiValued::Tags; 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::TagContainer; # ABSTRACT: Handle values with tags and validity ranges has _storage => ( is => 'rw', isa => class_type('Data::MultiValued::TagContainer'), init_arg => undef, lazy_build => 1, ); sub _build__storage { Data::MultiValued::TagContainer->new(); } sub _rebless_storage { my ($self) = @_; bless $self->{_storage},'Data::MultiValued::TagContainer'; } sub _as_hash { my ($self) = @_; my %ret = %{$self->_storage}; return {_storage=>\%ret}; } sub set { my ($self,%args) = validated_hash( \@_, tag => { isa => Str, optional => 1, }, value => { isa => Any, }, ); $self->_storage->get_or_create(\%args) ->{value} = $args{value}; } sub get { my ($self,%args) = validated_hash( \@_, tag => { isa => Str, optional => 1, }, ); $self->_storage->get(\%args) ->{value}; } sub clear { my ($self) = @_; $self->_clear_storage; } 1;