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