-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME
112 lines (83 loc) · 3.05 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
NAME
MouseX::AttributeHelpers - Extend your attribute interfaces
SYNOPSIS
package MyClass;
use Mouse;
use MouseX::AttributeHelpers;
has 'mapping' => (
metaclass => 'Collection::Hash',
is => 'rw',
isa => 'HashRef',
default => sub { +{} },
provides => {
exists => 'exists_in_mapping',
keys => 'ids_in_mapping',
get => 'get_mapping',
set => 'set_mapping',
},
);
package main;
my $obj = MyClass->new;
$obj->set_quantity(10); # quantity => 10
$obj->set_mapping(4, 'foo'); # 4 => 'foo'
$obj->set_mapping(5, 'bar'); # 5 => 'bar'
$obj->set_mapping(6, 'baz'); # 6 => 'baz'
# prints 'bar'
print $obj->get_mapping(5) if $obj->exists_in_mapping(5);
# prints '4, 5, 6'
print join ', ', $obj->ids_in_mapping;
DESCRIPTION
MouseX::AttributeHelpers provides commonly used attribute helper methods
for more specific types of data.
As seen in the "SYNOPSIS", you specify the extension via the "metaclass"
parameter.
PARAMETERS
provides
This points to a hashref that uses "provider" for the keys and "method"
for the values. The method will be added to the object itself and do
what you want.
curries
This points to a hashref that uses "provider" for the keys and has two
choices for the value:
You can supply "{ method => \@args }" for the values. The method will be
added to the object itself (always using @args as the beginning
arguments).
Another approach to curry a method provider is to supply a coderef
instead of an arrayref. The code ref takes $self, $body, and any
additional arguments passed to the final method.
METHOD PROVIDERS
Counter
Methods for incrementing and decrementing a counter attribute.
Number
Common numerical operations.
String
Common methods for string values.
Bool
Common methods for boolean values.
Collection::List
Common list methods for array references.
Collection::Array
Common methods for array references.
Collection::ImmutableHash
Common methods for hash references.
Collection::Hash
Common additional methods for hash references.
Collection::Bag
Methods for incrementing and decrementing a value of collection.
AUTHOR
NAKAGAWA Masaki <[email protected]>
THANKS TO
"AUTHOR" in MooseX::AttributeHelpers
LICENSE
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
SEE ALSO
Mouse
MouseX::AttributeHelpers::Counter, MouseX::AttributeHelpers::Number,
MouseX::AttributeHelpers::String, MouseX::AttributeHelpers::Bool,
MouseX::AttributeHelpers::Collection::List,
MouseX::AttributeHelpers::Collection::Array,
MouseX::AttributeHelpers::Collection::ImmutableHash,
MouseX::AttributeHelpers::Collection::Hash,
MouseX::AttributeHelpers::Collection::Bag
MooseX::AttributeHelpers