Commit | Line | Data |
e3c07b19 |
1 | |
c466e58f |
2 | package Moose::Meta::Attribute::Native::Trait::Hash; |
e3c07b19 |
3 | use Moose::Role; |
4 | |
96539d20 |
5 | our $VERSION = '0.87'; |
e3c07b19 |
6 | $VERSION = eval $VERSION; |
7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | |
c466e58f |
9 | use Moose::Meta::Attribute::Native::MethodProvider::Hash; |
e3c07b19 |
10 | |
c466e58f |
11 | with 'Moose::Meta::Attribute::Native::Trait'; |
e3c07b19 |
12 | |
13 | has 'method_provider' => ( |
14 | is => 'ro', |
15 | isa => 'ClassName', |
16 | predicate => 'has_method_provider', |
c466e58f |
17 | default => 'Moose::Meta::Attribute::Native::MethodProvider::Hash' |
e3c07b19 |
18 | ); |
19 | |
2e069f5a |
20 | sub _helper_type { 'HashRef' } |
e3c07b19 |
21 | |
22 | no Moose::Role; |
23 | |
e3c07b19 |
24 | 1; |
25 | |
26 | __END__ |
27 | |
28 | =pod |
29 | |
30 | =head1 NAME |
31 | |
c466e58f |
32 | Moose::Meta::Attribute::Native::Trait::Hash |
e3c07b19 |
33 | |
34 | =head1 SYNOPSIS |
35 | |
36 | package Stuff; |
37 | use Moose; |
e3c07b19 |
38 | |
39 | has 'options' => ( |
96fd0bec |
40 | traits => ['Hash'], |
e3c07b19 |
41 | is => 'ro', |
42 | isa => 'HashRef[Str]', |
43 | default => sub { {} }, |
5f3663b2 |
44 | handles => { |
45 | set_option => 'set', |
46 | get_option => 'get', |
47 | has_options => 'empty', |
48 | num_options => 'count', |
49 | delete_option => 'delete', |
e3c07b19 |
50 | } |
51 | ); |
52 | |
53 | =head1 DESCRIPTION |
54 | |
55 | This module provides a Hash attribute which provides a number of |
96fd0bec |
56 | hash-like operations. |
57 | |
58 | =head1 PROVIDED METHODS |
59 | |
60 | These methods are implemented in |
61 | L<Moose::Meta::Attribute::Native::MethodProvider::Hash>. |
62 | |
63 | =over 4 |
64 | |
65 | =item B<count> |
66 | |
67 | Returns the number of elements in the list. |
68 | |
69 | =item B<empty> |
70 | |
71 | If the list is populated, returns true. Otherwise, returns false. |
72 | |
73 | =item B<exists> |
74 | |
75 | Returns true if the given key is present in the hash |
76 | |
77 | =item B<defined> |
78 | |
79 | Returns true if the value of a given key is defined |
80 | |
81 | =item B<get> |
82 | |
83 | Returns an element of the hash by its key. |
84 | |
85 | =item B<keys> |
86 | |
87 | Returns the list of keys in the hash. |
88 | |
89 | =item B<values> |
90 | |
91 | Returns the list of values in the hash. |
92 | |
93 | =item B<kv> |
94 | |
95 | Returns the key, value pairs in the hash as array references |
96 | |
97 | =item B<elements> |
98 | |
99 | Returns the key, value pairs in the hash as a flattened list |
100 | |
101 | =item B<delete> |
102 | |
103 | Removes the element with the given key |
104 | |
105 | =item B<clear> |
106 | |
107 | Unsets the hash entirely. |
108 | |
109 | =item B<set> |
110 | |
111 | Sets the element in the hash at the given key to the given value. |
112 | |
113 | =item B<accessor> |
114 | |
115 | If passed one argument, returns the value of the requested key. If passed two |
116 | arguments, sets the value of the requested key. |
117 | |
118 | =back |
e3c07b19 |
119 | |
120 | =head1 METHODS |
121 | |
122 | =over 4 |
123 | |
124 | =item B<meta> |
125 | |
126 | =item B<method_provider> |
127 | |
128 | =item B<has_method_provider> |
129 | |
e3c07b19 |
130 | =back |
131 | |
132 | =head1 BUGS |
133 | |
134 | All complex software has bugs lurking in it, and this module is no |
135 | exception. If you find a bug please either email me, or add the bug |
136 | to cpan-RT. |
137 | |
138 | =head1 AUTHOR |
139 | |
140 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
141 | |
142 | =head1 COPYRIGHT AND LICENSE |
143 | |
144 | Copyright 2007-2009 by Infinity Interactive, Inc. |
145 | |
146 | L<http://www.iinteractive.com> |
147 | |
148 | This library is free software; you can redistribute it and/or modify |
149 | it under the same terms as Perl itself. |
150 | |
151 | =cut |