2 package Moose::Meta::Attribute::Native::Trait::Hash;
5 our $VERSION = '1.9900';
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 with 'Moose::Meta::Attribute::Native::Trait';
11 sub _helper_type { 'HashRef' }
23 Moose::Meta::Attribute::Native::Trait::Hash - Helper trait for HashRef attributes
33 isa => 'HashRef[Str]',
34 default => sub { {} },
38 has_no_options => 'is_empty',
39 num_options => 'count',
40 delete_option => 'delete',
47 This trait provides native delegation methods for array references.
49 =head1 PROVIDED METHODS
53 =item B<get($key, $key2, $key3...)>
55 Returns values from the hash.
57 In list context it returns a list of values in the hash for the given keys. In
58 scalar context it returns the value for the last key specified.
60 This method requires at least one argument.
62 =item B<set($key =E<gt> $value, $key2 =E<gt> $value2...)>
64 Sets the elements in the hash to the given values. It returns the new values
65 set for each key, in the same order as the keys passed to the method.
67 This method requires at least two arguments, and expects an even number of
70 =item B<delete($key, $key2, $key3...)>
72 Removes the elements with the given keys.
74 In list context it returns a list of values in the hash for the deleted
75 keys. In scalar context it returns the value for the last key specified.
79 Returns the list of keys in the hash.
81 This method does not accept any arguments.
85 Returns true if the given key is present in the hash.
87 This method requires a single argument.
89 =item B<defined($key)>
91 Returns true if the value of a given key is defined.
93 This method requires a single argument.
97 Returns the list of values in the hash.
99 This method does not accept any arguments.
103 Returns the key/value pairs in the hash as an array of array references.
105 for my $pair ( $object->options->pairs ) {
106 print "$pair->[0] = $pair->[1]\n";
109 This method does not accept any arguments.
113 Returns the key/value pairs in the hash as a flattened list..
115 This method does not accept any arguments.
119 Resets the hash to an empty value, like C<%hash = ()>.
121 This method does not accept any arguments.
125 Returns the number of elements in the hash. Also useful for not empty:
126 C<< has_options => 'count' >>.
128 This method does not accept any arguments.
132 If the hash is populated, returns false. Otherwise, returns true.
134 This method does not accept any arguments.
136 =item B<accessor($key)>
138 =item B<accessor($key, $value)>
140 If passed one argument, returns the value of the specified key. If passed two
141 arguments, sets the value of the specified key.
143 When called as a setter, this method returns the value that was set.
157 See L<Moose/BUGS> for details on reporting bugs.
161 Stevan Little E<lt>stevan@iinteractive.comE<gt>
163 =head1 COPYRIGHT AND LICENSE
165 Copyright 2007-2009 by Infinity Interactive, Inc.
167 L<http://www.iinteractive.com>
169 This library is free software; you can redistribute it and/or modify
170 it under the same terms as Perl itself.