1 package MooseX::AttributeHelpers::MethodProvider::Hash;
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
8 with 'MooseX::AttributeHelpers::MethodProvider::ImmutableHash';
11 my ($attr, $reader, $writer) = @_;
12 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
13 my $container_type_constraint = $attr->type_constraint->type_parameter;
15 my ( $self, @kvp ) = @_;
17 my ( @keys, @values );
20 my ( $key, $value ) = ( shift(@kvp), shift(@kvp) );
21 ($container_type_constraint->check($value))
22 || confess "Value " . ($value||'undef') . " did not pass container type constraint";
28 @{ $reader->($self) }{@keys} = @values;
30 $reader->($self)->{$keys[0]} = $values[0];
37 $reader->($_[0])->{$_[1]} = $_[2]
39 my ( $self, @kvp ) = @_;
40 my ( @keys, @values );
43 push @keys, shift @kvp;
44 push @values, shift @kvp;
47 @{ $reader->($_[0]) }{@keys} = @values;
54 my ($attr, $reader, $writer) = @_;
55 return sub { %{$reader->($_[0])} = () };
59 my ($attr, $reader, $writer) = @_;
61 my $hashref = $reader->(shift);
62 CORE::delete @{$hashref}{@_};
74 MooseX::AttributeHelpers::MethodProvider::Hash
78 This is a role which provides the method generators for
79 L<MooseX::AttributeHelpers::Collection::Hash>.
81 This role is composed from the
82 L<MooseX::AttributeHelpers::Collection::ImmutableHash> role.
92 =head1 PROVIDED METHODS
98 Returns the number of elements in the hash.
102 Removes the element with the given key
106 Returns true if the value of a given key is defined
110 If the list is populated, returns true. Otherwise, returns false.
114 Unsets the hash entirely.
118 Returns true if the given key is present in the hash
122 Returns an element of the hash by its key.
126 Returns the list of keys in the hash.
130 Sets the element in the hash at the given key to the given value.
134 Returns the list of values in the hash.
138 Returns the key, value pairs in the hash
144 All complex software has bugs lurking in it, and this module is no
145 exception. If you find a bug please either email me, or add the bug
150 Stevan Little E<lt>stevan@iinteractive.comE<gt>
152 =head1 COPYRIGHT AND LICENSE
154 Copyright 2007-2008 by Infinity Interactive, Inc.
156 L<http://www.iinteractive.com>
158 This library is free software; you can redistribute it and/or modify
159 it under the same terms as Perl itself.