diff options
author | Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> | 2011-11-24 17:59:04 +0000 |
---|---|---|
committer | Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> | 2011-11-24 17:59:55 +0000 |
commit | 6e5e90bf9e77324bb8a3455950a81c2abe626400 (patch) | |
tree | f247be78476d1af905baad0a1c9339eedbde13d9 /lib/Data/MultiValued.pm | |
parent | changelog bump (diff) | |
download | data-multivalued-6e5e90bf9e77324bb8a3455950a81c2abe626400.tar.gz data-multivalued-6e5e90bf9e77324bb8a3455950a81c2abe626400.tar.bz2 data-multivalued-6e5e90bf9e77324bb8a3455950a81c2abe626400.zip |
make PAUSE life easierv0.0.1_1
Diffstat (limited to 'lib/Data/MultiValued.pm')
-rw-r--r-- | lib/Data/MultiValued.pm | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/Data/MultiValued.pm b/lib/Data/MultiValued.pm new file mode 100644 index 0000000..aff7a17 --- /dev/null +++ b/lib/Data/MultiValued.pm @@ -0,0 +1,76 @@ +package Data::MultiValued; +use strict; +use warnings; +# ABSTRACT: store tag- and range-dependant data in a scalar or Moose attribute + +warn "Don't use this module directly, use Data::MultiValued::Tags or Data::MultiValued::Ranges or the like"; + +1; + +=head1 SYNOPSIS + + use Data::MultiValued::Tags; + + my $obj = Data::MultiValued::Tags->new(); + $obj->set({ + tag => 'tag1', + value => 'a string', + }); + say $obj->get({tag=>'tag1'}); # prints 'a string' + say $obj->get({tag=>'tag2'}); # dies + +Also: + + package My::Class; + use Moose; + use Data::MultiValued::AttributeTrait::Tags; + + has stuff => ( + is => 'rw', + isa => 'Int', + traits => ['MultiValued::Tags'], + ); + + # later + + my $obj = My::Class->new(); + $obj->stuff_multi({tag=>'tag1'},123); + say $obj->stuff_multi({tag=>'tag1'}); # prints 123 + +=head1 DESCRIPTION + +This set of classes allows you to store different values inside a +single object, and access them by tag and / or by a numeric value. + +Yes, you could do the same with hashes and some clever use of +arrays. Or you could use L<Array::IntSpan>. Or some other CPAN +module. Why use these? + +=over 4 + +=item * + +they are optimised for serialisation, see +L<Data::MultiValued::UglySerializationHelperRole> and F<t/json.t>. + +=item * + +you get accessors generated for your Moose attributes just by setting +a trait + +=item * + +tags and ranges interact in sensible ways, including clearing ranges + +=back + +=head1 Where to go from here + +Look at the tests for detailed examples of usage. Look at +L<Data::MultiValued::Tags>, L<Data::MultiValued::Ranges> and +L<Data::MultiValued::TagsAndRanges> for the containers +themselves. Look at L<Data::MultiValued::AttributeTrait::Tags>, +L<Data::MultiValued::AttributeTrait::Ranges> and +L<Data::MultiValued::AttributeTrait::TagsAndRanges> for the Moose +attribute traits. + |