1 package MooseX::AttributeHelpers::MethodProvider::Hash;
4 our $VERSION = '0.12_01';
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
120 All complex software has bugs lurking in it, and this module is no
121 exception. If you find a bug please either email me, or add the bug
126 Stevan Little E<lt>stevan@iinteractive.comE<gt>
128 =head1 COPYRIGHT AND LICENSE
130 Copyright 2007-2008 by Infinity Interactive, Inc.
132 L<http://www.iinteractive.com>
134 This library is free software; you can redistribute it and/or modify
135 it under the same terms as Perl itself.