2 package MooseX::AttributeHelpers::Collection::Hash;
4 use Moose::Util::TypeConstraints;
7 our $AUTHORITY = 'cpan:STEVAN';
9 extends 'MooseX::AttributeHelpers::Base';
11 has '+method_constructors' => (
16 return sub { $attr->get_value($_[0])->{$_[1]} };
20 return sub { $attr->get_value($_[0])->{$_[1]} = $_[2] };
24 return sub { scalar keys %{$attr->get_value($_[0])} };
28 return sub { scalar keys %{$attr->get_value($_[0])} ? 1 : 0 };
34 sub _process_options_for_provides {
35 my ($self, $options) = @_;
36 (exists $options->{isa})
37 || confess "You must define a type with the Hash metaclass";
39 my $isa = $options->{isa};
41 unless (blessed($isa) && $isa->isa('Moose::Meta::TypeConstraint')) {
42 $isa = find_type_constraint($isa);
45 ($isa->is_a_type_of('HashRef'))
46 || confess "The type constraint for a Hash ($options->{isa}) must be a subtype of HashRef";
50 no Moose::Util::TypeConstraints;
52 # register the alias ...
53 package Moose::Meta::Attribute::Custom::Collection::Hash;
54 sub register_implementation { 'MooseX::AttributeHelpers::Collection::Hash' }
73 All complex software has bugs lurking in it, and this module is no
74 exception. If you find a bug please either email me, or add the bug
79 Stevan Little E<lt>stevan@iinteractive.comE<gt>
81 =head1 COPYRIGHT AND LICENSE
83 Copyright 2007 by Infinity Interactive, Inc.
85 L<http://www.iinteractive.com>
87 This library is free software; you can redistribute it and/or modify
88 it under the same terms as Perl itself.