1Moose::Meta::Attribute:U:sNeartiCvoen(t3r)ibuted Perl DoMcouomseen:t:aMteitoan::Attribute::Native(3)
2
3
4

NAME

6       Moose::Meta::Attribute::Native - Extend your attribute interfaces
7

SYNOPSIS

9         package MyClass;
10         use Moose;
11
12         has 'mapping' => (
13             traits    => [ 'Hash' ],
14             is        => 'rw',
15             isa       => 'HashRef[Str]',
16             default   => sub { {} },
17             handles   => {
18                 exists_in_mapping => 'exists',
19                 ids_in_mapping    => 'keys',
20                 get_mapping       => 'get',
21                 set_mapping       => 'set',
22                 set_quantity      => [ set => 'quantity' ],
23             },
24         );
25
26
27         # ...
28
29         my $obj = MyClass->new;
30         $obj->set_quantity(10);      # quantity => 10
31         $obj->set_mapping('foo', 4); # foo => 4
32         $obj->set_mapping('bar', 5); # bar => 5
33         $obj->set_mapping('baz', 6); # baz => 6
34
35
36         # prints 5
37         print $obj->get_mapping('bar') if $obj->exists_in_mapping('bar');
38
39         # prints 'quantity, foo, bar, baz'
40         print join ', ', $obj->ids_in_mapping;
41

DESCRIPTION

43       While Moose attributes provide a way to name your accessors, readers,
44       writers, clearers and predicates, this set of traits provides commonly
45       used attribute helper methods for more specific types of data.
46
47       As seen in the "SYNOPSIS", you specify the data structure via the
48       "trait" parameter. Available traits are below; see "METHOD PROVIDERS".
49
50       This module used to exist as the MooseX::AttributeHelpers extension. It
51       was very commonly used, so we moved it into core Moose. Since this gave
52       us a chance to change the interface, you will have to change your code
53       or continue using the MooseX::AttributeHelpers extension.
54       MooseX::AttributeHelpers should continue to work.
55

PARAMETERS

57   handles
58       This is like "handles" in "has" in Moose, but only HASH references are
59       allowed.  Keys are method names that you want installed locally, and
60       values are methods from the method providers (below).  Currying with
61       delegated methods works normally for "handles".
62

METHOD PROVIDERS

64       Number
65           Common numerical operations.
66
67               has 'integer' => (
68                   traits    => ['Number'],
69                   is        => 'ro',
70                   isa       => 'Int',
71                   default   => 5,
72                   handles   => {
73                       set => 'set',
74                       add => 'add',
75                       sub => 'sub',
76                       mul => 'mul',
77                       div => 'div',
78                       mod => 'mod',
79                       abs => 'abs',
80                       # ...
81                   }
82               );
83
84       String
85           Common methods for string operations.
86
87               has 'text' => (
88                   traits    => ['String'],
89                   is        => 'rw',
90                   isa       => 'Str',
91                   default   => q{},
92                   handles   => {
93                       add_text     => 'append',
94                       replace_text => 'replace',
95                       # ...
96                   }
97               );
98
99       Counter
100           Methods for incrementing and decrementing a counter attribute.
101
102               has 'counter' => (
103                   traits    => ['Counter'],
104                   is        => 'ro',
105                   isa       => 'Num',
106                   default   => 0,
107                   handles   => {
108                       inc_counter   => 'inc',
109                       dec_counter   => 'dec',
110                       reset_counter => 'reset',
111                       # ...
112                   }
113               );
114
115       Bool
116           Common methods for boolean values.
117
118               has 'is_lit' => (
119                   traits    => ['Bool'],
120                   is        => 'rw',
121                   isa       => 'Bool',
122                   default   => 0,
123                   handles   => {
124                       illuminate  => 'set',
125                       darken      => 'unset',
126                       flip_switch => 'toggle',
127                       is_dark     => 'not',
128                       # ...
129                   }
130               );
131
132       Hash
133           Common methods for hash references.
134
135               has 'options' => (
136                   traits    => ['Hash'],
137                   is        => 'ro',
138                   isa       => 'HashRef[Str]',
139                   default   => sub { {} },
140                   handles   => {
141                       set_option => 'set',
142                       get_option => 'get',
143                       has_option => 'exists',
144                       # ...
145                   }
146               );
147
148       Array
149           Common methods for array references.
150
151               has 'queue' => (
152                   traits    => ['Array'],
153                   is        => 'ro',
154                   isa       => 'ArrayRef[Str]',
155                   default   => sub { [] },
156                   handles   => {
157                       add_item  => 'push',
158                       next_item => 'shift',
159                       # ...
160                   }
161               );
162
163       Code
164           Common methods for code references.
165
166               has 'callback' => (
167                   traits    => ['Code'],
168                   is        => 'ro',
169                   isa       => 'CodeRef',
170                   default   => sub { sub { 'called' } },
171                   handles   => {
172                       call => 'execute',
173                       # ...
174                   }
175               );
176

BUGS

178       See "BUGS" in Moose for details on reporting bugs.
179

AUTHOR

181       Stevan Little <stevan@iinteractive.com>
182
183       with contributions from:
184
185       Robert (rlb3) Boone
186
187       Paul (frodwith) Driver
188
189       Shawn (Sartak) Moore
190
191       Chris (perigrin) Prather
192
193       Robert (phaylon) Sedlacek
194
195       Tom (dec) Lanyon
196
197       Yuval Kogman
198
199       Jason May
200
201       Cory (gphat) Watson
202
203       Florian (rafl) Ragwitz
204
205       Evan Carroll
206
207       Jesse (doy) Luehrs
208
209       Jay Hannah
210
211       Robert Buels
212
214       Copyright 2007-2009 by Infinity Interactive, Inc.
215
216       <http://www.iinteractive.com>
217
218       This library is free software; you can redistribute it and/or modify it
219       under the same terms as Perl itself.
220
221
222
223perl v5.12.2                      2010-08-28 Moose::Meta::Attribute::Native(3)
Impressum