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