1MooseX::AttributeHelperUss(e3r)Contributed Perl DocumentMaotoisoenX::AttributeHelpers(3)
2
3
4
6 MooseX::AttributeHelpers - Extend your attribute interfaces
7
9 package MyClass;
10 use Moose;
11 use MooseX::AttributeHelpers;
12
13 has 'mapping' => (
14 metaclass => 'Collection::Hash',
15 is => 'rw',
16 isa => 'HashRef[Str]',
17 default => sub { {} },
18 provides => {
19 exists => 'exists_in_mapping',
20 keys => 'ids_in_mapping',
21 get => 'get_mapping',
22 set => 'set_mapping',
23 },
24 );
25
26 # ...
27
28 my $obj = MyClass->new;
29 $obj->set_mapping(4, 'foo');
30 $obj->set_mapping(5, 'bar');
31 $obj->set_mapping(6, 'baz');
32
33 # prints 'bar'
34 print $obj->get_mapping(5) if $obj->exists_in_mapping(5);
35
36 # prints '4, 5, 6'
37 print join ', ', $obj->ids_in_mapping;
38
40 While Moose attributes provide you with a way to name your accessors,
41 readers, writers, clearers and predicates, this library provides com‐
42 monly used attribute helper methods for more specific types of data.
43
44 As seen in the "SYNOPSIS", you specify the extension via the "meta‐
45 class" parameter. Available meta classes are:
46
47 Number
48 Common numerical operations.
49
50 Counter
51 Methods for incrementing and decrementing a counter attribute.
52
53 Collection::Hash
54 Common methods for hash references.
55
56 Collection::Array
57 Common methods for array references.
58
59 Collection::List
60 Common list methods for array references.
61
63 This is an early release of this module. Right now it is in great need
64 of documentation and tests in the test suite. However, we have used
65 this module to great success at $work where it has been tested very
66 thoroughly and deployed into a major production site.
67
68 I plan on getting better docs and tests in the next few releases, but
69 until then please refer to the few tests we do have and feel free email
70 and/or message me on irc.perl.org if you have any questions.
71
73 We need tests and docs badly.
74
76 All complex software has bugs lurking in it, and this module is no
77 exception. If you find a bug please either email me, or add the bug to
78 cpan-RT.
79
81 Stevan Little <stevan@iinteractive.com>
82
83 with contributions from:
84
85 Robert (rlb3) Boone
86
87 Chris (perigrin) Prather
88
89 Robert (phaylon) Sedlacek
90
91 Tom (dec) Lanyon
92
93 Yuval Kogman
94
96 Copyright 2007, 2008 by Infinity Interactive, Inc.
97
98 <http://www.iinteractive.com>
99
100 This library is free software; you can redistribute it and/or modify it
101 under the same terms as Perl itself.
102
103
104
105perl v5.8.8 2008-01-06 MooseX::AttributeHelpers(3)