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