1 package MooseX::AttributeHelpers::MethodProvider::Hash;
5 our $AUTHORITY = 'cpan:STEVAN';
7 with 'MooseX::AttributeHelpers::MethodProvider::ImmutableHash';
10 my ($attr, $reader, $writer) = @_;
11 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
12 my $container_type_constraint = $attr->type_constraint->type_parameter;
14 my ( $self, @kvp ) = @_;
16 my ( @keys, @values );
19 my ( $key, $value ) = ( shift(@kvp), shift(@kvp) );
20 ($container_type_constraint->check($value))
21 || confess "Value " . ($value||'undef') . " did not pass container type constraint";
27 @{ $reader->($self) }{@keys} = @values;
29 $reader->($self)->{$keys[0]} = $values[0];
36 $reader->($_[0])->{$_[1]} = $_[2]
38 my ( $self, @kvp ) = @_;
39 my ( @keys, @values );
42 push @keys, shift @kvp;
43 push @values, shift @kvp;
46 @{ $reader->($_[0]) }{@keys} = @values;
53 my ($attr, $reader, $writer) = @_;
54 return sub { %{$reader->($_[0])} = () };
58 my ($attr, $reader, $writer) = @_;
59 return sub { CORE::delete $reader->($_[0])->{$_[1]} };
70 MooseX::AttributeHelpers::MethodProvider::Hash
74 This is a role which provides the method generators for
75 L<MooseX::AttributeHelpers::Collection::Hash>.
77 This role is composed from the
78 L<MooseX::AttributeHelpers::Collection::ImmutableHash> role.
88 =head1 PROVIDED METHODS
116 All complex software has bugs lurking in it, and this module is no
117 exception. If you find a bug please either email me, or add the bug
122 Stevan Little E<lt>stevan@iinteractive.comE<gt>
124 =head1 COPYRIGHT AND LICENSE
126 Copyright 2007-2008 by Infinity Interactive, Inc.
128 L<http://www.iinteractive.com>
130 This library is free software; you can redistribute it and/or modify
131 it under the same terms as Perl itself.