2 package Moose::AttributeHelpers;
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
10 use Moose::Meta::Attribute::Trait::Native::Bool;
11 use Moose::Meta::Attribute::Trait::Native::Counter;
12 use Moose::Meta::Attribute::Trait::Native::Number;
13 use Moose::Meta::Attribute::Trait::Native::String;
14 use Moose::Meta::Attribute::Trait::Native::Array;
15 use Moose::Meta::Attribute::Trait::Native::Hash;
25 Moose::AttributeHelpers - Extend your attribute interfaces
31 use Moose::AttributeHelpers;
36 isa => 'HashRef[Str]',
37 default => sub { {} },
39 exists_in_mapping => 'exists',
40 ids_in_mapping => 'keys',
43 set_quantity => [ set => [ 'quantity' ] ],
50 my $obj = MyClass->new;
51 $obj->set_quantity(10); # quantity => 10
52 $obj->set_mapping(4, 'foo'); # 4 => 'foo'
53 $obj->set_mapping(5, 'bar'); # 5 => 'bar'
54 $obj->set_mapping(6, 'baz'); # 6 => 'baz'
58 print $obj->get_mapping(5) if $obj->exists_in_mapping(5);
61 print join ', ', $obj->ids_in_mapping;
65 While L<Moose> attributes provide you with a way to name your accessors,
66 readers, writers, clearers and predicates, this library provides commonly
67 used attribute helper methods for more specific types of data.
69 As seen in the L</SYNOPSIS>, you specify the extension via the
70 C<trait> parameter. Available meta classes are below; see L</METHOD PROVIDERS>.
72 This module used to exist as the L<MooseX::AttributeHelpers> extension. It was
73 very commonly used, so we moved it into core Moose. Since this gave us a chance
74 to change the interface, you will have to change your code or continue using
75 the L<MooseX::AttributeHelpers> extension.
81 This is like C<< handles >> in L<Moose/has>, but only HASH references are
82 allowed. Keys are method names that you want installed locally, and values are
83 methods from the method providers (below). Currying with delegated methods
84 works normally for C<< handles >>.
86 =head1 METHOD PROVIDERS
90 =item L<Number|Moose::Meta::Attribute::Trait::Native::Number>
92 Common numerical operations.
94 =item L<String|Moose::Meta::Attribute::Trait::Native::String>
96 Common methods for string operations.
98 =item L<Counter|Moose::Meta::Attribute::Trait::Native::Counter>
100 Methods for incrementing and decrementing a counter attribute.
102 =item L<Bool|Moose::Meta::Attribute::Trait::Native::Bool>
104 Common methods for boolean values.
106 =item L<Hash|Moose::Meta::Attribute::Trait::Native::Hash>
108 Common methods for hash references.
110 =item L<ImmutableHash|Moose::Meta::Attribute::Trait::Native::ImmutableHash>
112 Common methods for inspecting hash references.
114 =item L<Array|Moose::Meta::Attribute::Trait::Native::Array>
116 Common methods for array references.
118 =item L<List|Moose::Meta::Attribute::Trait::Native::List>
120 Common list methods for array references.
126 All complex software has bugs lurking in it, and this module is no
127 exception. If you find a bug please either email me, or add the bug
132 Stevan Little E<lt>stevan@iinteractive.comE<gt>
134 B<with contributions from:>
138 Paul (frodwith) Driver
142 Chris (perigrin) Prather
144 Robert (phaylon) Sedlacek
154 Florian (rafl) Ragwitz
160 =head1 COPYRIGHT AND LICENSE
162 Copyright 2007-2009 by Infinity Interactive, Inc.
164 L<http://www.iinteractive.com>
166 This library is free software; you can redistribute it and/or modify
167 it under the same terms as Perl itself.