ad9e9be2c127b77679033983a9e978cdb95b7f74
[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
29   has mapping => (
30       metaclass => 'Collection::Hash',
31       is        => 'rw',
32       isa       => 'HashRef',
33       default   => sub { {} },
34       provides  => {
35           exists    => 'exists_in_mapping',
36           keys      => 'ids_in_mapping',
37           get       => 'get_mapping',
38           set       => 'set_mapping',
39       },
40   );
41
42   # ...
43
44   my $obj = MyClass->new;
45   $obj->set_mapping(4, 'foo');
46   $obj->set_mapping(5, 'bar');
47   $obj->set_mapping(6, 'baz');
48
49   # prints 'bar'
50   print $obj->get_mapping(5) if $obj->exists_in_mapping(5);
51
52   # prints '4, 5, 6'
53   print join ', ', $obj->ids_in_mapping;
54
55 =head1 DESCRIPTION
56
57 While L<Moose> attributes provide you with a way to name your accessors,
58 readers, writers, clearers and predicates, this library provides commonly
59 used attribute helper methods for more specific types of data.
60
61 As seen in the L</SYNOPSIS>, you specify the extension via the 
62 C<metaclass> parameter. Available meta classes are:
63
64 =over
65
66 =item L<Number|MooseX::AttributeHelpers::Number>
67
68 Common numerical operations.
69
70 =item L<Counter|MooseX::AttributeHelpers::Counter>
71
72 Methods for incrementing and decrementing a counter attribute.
73
74 =item L<Collection::Hash|MooseX::AttributeHelpers::Collection::Hash>
75
76 Common methods for hash references.
77
78 =item L<Collection::Array|MooseX::AttributeHelpers::Collection::Array>
79
80 Common methods for array references.
81
82 =back
83
84 =head1 BUGS
85
86 All complex software has bugs lurking in it, and this module is no 
87 exception. If you find a bug please either email me, or add the bug
88 to cpan-RT.
89
90 =head1 AUTHOR
91
92 Stevan Little E<lt>stevan@iinteractive.comE<gt>
93
94 =head1 COPYRIGHT AND LICENSE
95
96 Copyright 2007 by Infinity Interactive, Inc.
97
98 L<http://www.iinteractive.com>
99
100 This library is free software; you can redistribute it and/or modify
101 it under the same terms as Perl itself.
102
103 =cut