package Data::MultiValued::AttributeTrait::Tags; use Moose::Role; use namespace::autoclean; use Data::MultiValued::Tags; with 'Data::MultiValued::AttributeTrait'; # ABSTRACT: attribute traits for attributes holding tagged values =head1 SYNOPSIS package My::Class; use Moose; use Data::MultiValued::AttributeTrait::Tags; has stuff => ( is => 'rw', isa => 'Int', traits => ['MultiValued::Tags'], predicate => 'has_stuff', multi_accessor => 'stuff_tagged', multi_predicate => 'has_stuff_tagged', ); =head1 DESCRIPTION This role consumes L and specialises it to use L as multi-value storage: =head2 C Returns C<'Data::MultiValued::Tags'>. =head2 C Returns C<('tag')>. =head2 C Returns C<('tag')>. =head2 C my @tags = $obj->meta->get_attribute('my_attr')->all_tags($obj); Returns a list of all values for which C<< $obj->has_my_attr_multi({tag=>$tag}) >> would return true. =cut sub multivalue_storage_class { 'Data::MultiValued::Tags' }; sub opts_to_pass_set { qw(tag) } sub opts_to_pass_get { qw(tag) } sub all_tags { my ($self,$instance) = @_; my $storage = $self->get_full_storage($instance); return () unless $storage; my @tags = $storage->_storage->all_tags; if ($storage->_storage->_has_default_tag) { push @tags,undef; } return @tags; } package Moose::Meta::Attribute::Custom::Trait::MultiValued::Tags;{ sub register_implementation { 'Data::MultiValued::AttributeTrait::Tags' } } 1;