Trait::Collection::ImmutableHash
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers.pm
1
2 package MooseX::AttributeHelpers;
3
4 our $VERSION   = '0.08';
5 our $AUTHORITY = 'cpan:STEVAN';
6
7 use MooseX::AttributeHelpers::Meta::Method::Provided;
8
9 use MooseX::AttributeHelpers::Trait::Counter;
10 use MooseX::AttributeHelpers::Trait::Number;
11 use MooseX::AttributeHelpers::Trait::String;
12 use MooseX::AttributeHelpers::Trait::Collection::List;
13 use MooseX::AttributeHelpers::Trait::Collection::Array;
14 use MooseX::AttributeHelpers::Trait::Collection::Hash;
15 use MooseX::AttributeHelpers::Trait::Collection::ImmutableHash;
16
17 use MooseX::AttributeHelpers::Counter;
18 use MooseX::AttributeHelpers::Number;
19 use MooseX::AttributeHelpers::String;
20 use MooseX::AttributeHelpers::Collection::List;
21 use MooseX::AttributeHelpers::Collection::Array;
22 use MooseX::AttributeHelpers::Collection::Hash;
23 use MooseX::AttributeHelpers::Collection::ImmutableHash;
24 use MooseX::AttributeHelpers::Collection::Bag;
25
26 1;
27
28 __END__
29
30 =pod
31
32 =head1 NAME
33
34 MooseX::AttributeHelpers - Extend your attribute interfaces
35
36 =head1 SYNOPSIS
37
38   package MyClass;
39   use Moose;
40   use MooseX::AttributeHelpers;
41
42   has 'mapping' => (
43       metaclass => 'Collection::Hash',
44       is        => 'rw',
45       isa       => 'HashRef[Str]',
46       default   => sub { {} },
47       provides  => {
48           exists    => 'exists_in_mapping',
49           keys      => 'ids_in_mapping',
50           get       => 'get_mapping',
51           set       => 'set_mapping',
52       },
53   );
54
55   # ...
56
57   my $obj = MyClass->new;
58   $obj->set_mapping(4, 'foo');
59   $obj->set_mapping(5, 'bar');
60   $obj->set_mapping(6, 'baz');
61
62   # prints 'bar'
63   print $obj->get_mapping(5) if $obj->exists_in_mapping(5);
64
65   # prints '4, 5, 6'
66   print join ', ', $obj->ids_in_mapping;
67
68 =head1 DESCRIPTION
69
70 While L<Moose> attributes provide you with a way to name your accessors,
71 readers, writers, clearers and predicates, this library provides commonly
72 used attribute helper methods for more specific types of data.
73
74 As seen in the L</SYNOPSIS>, you specify the extension via the 
75 C<metaclass> parameter. Available meta classes are:
76
77 =over
78
79 =item L<Number|MooseX::AttributeHelpers::Number>
80
81 Common numerical operations.
82
83 =item L<Counter|MooseX::AttributeHelpers::Counter>
84
85 Methods for incrementing and decrementing a counter attribute.
86
87 =item L<Collection::Hash|MooseX::AttributeHelpers::Collection::Hash>
88
89 Common methods for hash references.
90
91 =item L<Collection::Array|MooseX::AttributeHelpers::Collection::Array>
92
93 Common methods for array references.
94
95 =item L<Collection::List|MooseX::AttributeHelpers::Collection::List>
96
97 Common list methods for array references. 
98
99 =back
100
101 =head1 CAVEAT
102
103 This is an early release of this module. Right now it is in great need 
104 of documentation and tests in the test suite. However, we have used this 
105 module to great success at C<$work> where it has been tested very thoroughly
106 and deployed into a major production site.
107
108 I plan on getting better docs and tests in the next few releases, but until 
109 then please refer to the few tests we do have and feel free email and/or 
110 message me on irc.perl.org if you have any questions.
111
112 =head1 TODO
113
114 We need tests and docs badly.
115
116 =head1 BUGS
117
118 All complex software has bugs lurking in it, and this module is no 
119 exception. If you find a bug please either email me, or add the bug
120 to cpan-RT.
121
122 =head1 AUTHOR
123
124 Stevan Little E<lt>stevan@iinteractive.comE<gt>
125
126 B<with contributions from:>
127
128 Robert (rlb3) Boone
129
130 Chris (perigrin) Prather
131
132 Robert (phaylon) Sedlacek
133
134 Tom (dec) Lanyon
135
136 Yuval Kogman
137
138 =head1 COPYRIGHT AND LICENSE
139
140 Copyright 2007, 2008 by Infinity Interactive, Inc.
141
142 L<http://www.iinteractive.com>
143
144 This library is free software; you can redistribute it and/or modify
145 it under the same terms as Perl itself.
146
147 =cut