Commit | Line | Data |
e3c07b19 |
1 | |
c466e58f |
2 | package Moose::Meta::Attribute::Native::Trait::Hash; |
e3c07b19 |
3 | use Moose::Role; |
4 | |
122a129a |
5 | our $VERSION = '0.89'; |
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 => { |
af44c00c |
45 | set_option => 'set', |
46 | get_option => 'get', |
47 | has_no_options => 'empty', |
48 | num_options => 'count', |
49 | delete_option => 'delete', |
8396a437 |
50 | pairs => 'kv', |
9610c1d2 |
51 | }, |
e3c07b19 |
52 | ); |
53 | |
54 | =head1 DESCRIPTION |
55 | |
56 | This module provides a Hash attribute which provides a number of |
8396a437 |
57 | hash-like operations. |
96fd0bec |
58 | |
59 | =head1 PROVIDED METHODS |
60 | |
61 | These methods are implemented in |
62 | L<Moose::Meta::Attribute::Native::MethodProvider::Hash>. |
63 | |
64 | =over 4 |
65 | |
8396a437 |
66 | =item B<get($key)> |
96fd0bec |
67 | |
8396a437 |
68 | Returns an element of the hash by its key. |
96fd0bec |
69 | |
8396a437 |
70 | =item B<set($key)> |
96fd0bec |
71 | |
8396a437 |
72 | Sets the element in the hash at the given key to the given value. |
96fd0bec |
73 | |
8396a437 |
74 | =item B<delete($key)> |
96fd0bec |
75 | |
8396a437 |
76 | Removes the element with the given key. |
96fd0bec |
77 | |
8396a437 |
78 | =item B<keys> |
96fd0bec |
79 | |
8396a437 |
80 | Returns the list of keys in the hash. |
96fd0bec |
81 | |
8396a437 |
82 | =item B<exists($key)> |
96fd0bec |
83 | |
8396a437 |
84 | Returns true if the given key is present in the hash. |
96fd0bec |
85 | |
8396a437 |
86 | =item B<defined($key)> |
96fd0bec |
87 | |
8396a437 |
88 | Returns true if the value of a given key is defined. |
96fd0bec |
89 | |
90 | =item B<values> |
91 | |
92 | Returns the list of values in the hash. |
93 | |
94 | =item B<kv> |
95 | |
8396a437 |
96 | Returns the key/value pairs in the hash as an array of array references. |
97 | |
98 | for my $pair ( $object->options->pairs ) { |
99 | print "$pair->[0] = $pair->[1]\n"; |
100 | } |
96fd0bec |
101 | |
102 | =item B<elements> |
103 | |
8396a437 |
104 | Returns the key/value pairs in the hash as a flattened list.. |
96fd0bec |
105 | |
8396a437 |
106 | =item B<clear> |
96fd0bec |
107 | |
8396a437 |
108 | Resets the hash to an empty value, like C<%hash = ()>. |
96fd0bec |
109 | |
8396a437 |
110 | =item B<count> |
96fd0bec |
111 | |
8396a437 |
112 | Returns the number of elements in the hash. |
96fd0bec |
113 | |
8396a437 |
114 | =item B<empty> |
96fd0bec |
115 | |
8396a437 |
116 | If the hash is populated, returns false. Otherwise, returns true. |
96fd0bec |
117 | |
118 | =item B<accessor> |
119 | |
8396a437 |
120 | If passed one argument, returns the value of the specified key. If passed two |
121 | arguments, sets the value of the specified key. |
96fd0bec |
122 | |
123 | =back |
e3c07b19 |
124 | |
125 | =head1 METHODS |
126 | |
127 | =over 4 |
128 | |
129 | =item B<meta> |
130 | |
131 | =item B<method_provider> |
132 | |
133 | =item B<has_method_provider> |
134 | |
e3c07b19 |
135 | =back |
136 | |
137 | =head1 BUGS |
138 | |
139 | All complex software has bugs lurking in it, and this module is no |
140 | exception. If you find a bug please either email me, or add the bug |
141 | to cpan-RT. |
142 | |
143 | =head1 AUTHOR |
144 | |
145 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
146 | |
147 | =head1 COPYRIGHT AND LICENSE |
148 | |
149 | Copyright 2007-2009 by Infinity Interactive, Inc. |
150 | |
151 | L<http://www.iinteractive.com> |
152 | |
153 | This library is free software; you can redistribute it and/or modify |
154 | it under the same terms as Perl itself. |
155 | |
156 | =cut |