2 package Moose::AttributeHelpers;
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
10 use Moose::AttributeHelpers::Trait::Bool;
11 use Moose::AttributeHelpers::Trait::Counter;
12 use Moose::AttributeHelpers::Trait::Number;
13 use Moose::AttributeHelpers::Trait::String;
14 use Moose::AttributeHelpers::Trait::Collection::List;
15 use Moose::AttributeHelpers::Trait::Collection::Array;
16 use Moose::AttributeHelpers::Trait::Collection::Hash;
17 use Moose::AttributeHelpers::Trait::Collection::ImmutableHash;
18 use Moose::AttributeHelpers::Trait::Collection::Bag;
20 use Moose::AttributeHelpers::Counter;
21 use Moose::AttributeHelpers::Number;
22 use Moose::AttributeHelpers::String;
23 use Moose::AttributeHelpers::Bool;
24 use Moose::AttributeHelpers::Collection::List;
25 use Moose::AttributeHelpers::Collection::Array;
26 use Moose::AttributeHelpers::Collection::Hash;
27 use Moose::AttributeHelpers::Collection::ImmutableHash;
28 use Moose::AttributeHelpers::Collection::Bag;
38 Moose::AttributeHelpers - Extend your attribute interfaces
44 use Moose::AttributeHelpers;
47 metaclass => 'Collection::Hash',
49 isa => 'HashRef[Str]',
50 default => sub { {} },
52 exists_in_mapping => 'exists',
53 ids_in_mapping => 'keys',
56 set_quantity => [ set => [ 'quantity' ] ],
63 my $obj = MyClass->new;
64 $obj->set_quantity(10); # quantity => 10
65 $obj->set_mapping(4, 'foo'); # 4 => 'foo'
66 $obj->set_mapping(5, 'bar'); # 5 => 'bar'
67 $obj->set_mapping(6, 'baz'); # 6 => 'baz'
71 print $obj->get_mapping(5) if $obj->exists_in_mapping(5);
74 print join ', ', $obj->ids_in_mapping;
78 While L<Moose> attributes provide you with a way to name your accessors,
79 readers, writers, clearers and predicates, this library provides commonly
80 used attribute helper methods for more specific types of data.
82 As seen in the L</SYNOPSIS>, you specify the extension via the
83 C<trait> parameter. Available meta classes are below; see L</METHOD PROVIDERS>.
89 This is like C<< handles >> in L<Moose/has>, but only HASH references are
90 allowed. Keys are method names that you want installed locally, and values are
91 methods from the method providers (below). Currying with delegated methods works normally for C<< handles >>.
93 =head1 METHOD PROVIDERS
97 =item L<Number|Moose::AttributeHelpers::Trait::Number>
99 Common numerical operations.
101 =item L<String|Moose::AttributeHelpers::Trait::String>
103 Common methods for string operations.
105 =item L<Counter|Moose::AttributeHelpers::Trait::Counter>
107 Methods for incrementing and decrementing a counter attribute.
109 =item L<Bool|Moose::AttributeHelpers::Trait::Bool>
111 Common methods for boolean values.
113 =item L<Collection::Hash|Moose::AttributeHelpers::Trait::Collection::Hash>
115 Common methods for hash references.
117 =item L<Collection::ImmutableHash|Moose::AttributeHelpers::Trait::Collection::ImmutableHash>
119 Common methods for inspecting hash references.
121 =item L<Collection::Array|Moose::AttributeHelpers::Trait::Collection::Array>
123 Common methods for array references.
125 =item L<Collection::List|Moose::AttributeHelpers::Trait::Collection::List>
127 Common list methods for array references.
133 This is an early release of this module. Right now it is in great need
134 of documentation and tests in the test suite. However, we have used this
135 module to great success at C<$work> where it has been tested very thoroughly
136 and deployed into a major production site.
138 I plan on getting better docs and tests in the next few releases, but until
139 then please refer to the few tests we do have and feel free email and/or
140 message me on irc.perl.org if you have any questions.
144 We need tests and docs badly.
148 All complex software has bugs lurking in it, and this module is no
149 exception. If you find a bug please either email me, or add the bug
154 Stevan Little E<lt>stevan@iinteractive.comE<gt>
156 B<with contributions from:>
160 Paul (frodwith) Driver
164 Chris (perigrin) Prather
166 Robert (phaylon) Sedlacek
176 Florian (rafl) Ragwitz
182 =head1 COPYRIGHT AND LICENSE
184 Copyright 2007-2009 by Infinity Interactive, Inc.
186 L<http://www.iinteractive.com>
188 This library is free software; you can redistribute it and/or modify
189 it under the same terms as Perl itself.