summaryrefslogtreecommitdiff
path: root/lib/Data/MultiValued.pm
blob: 7b277c980f34f790eabee17924ba148be31d50a6 (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
package Data::MultiValued; 
{
  $Data::MultiValued::VERSION = '0.0.6_1';
}
{
  $Data::MultiValued::DIST = '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;
 
 
__END__
=pod
 
=encoding utf-8
 
=head1 NAME
 
Data::MultiValued - store tag- and range-dependant data in a scalar or Moose attribute
 
=head1 VERSION
 
version 0.0.6_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.
 
=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