fixing this to work correctly
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / Collection / Hash.pm
CommitLineData
22d869ff 1
2package MooseX::AttributeHelpers::Collection::Hash;
d26633fc 3use Moose;
88aaf2bd 4use Moose::Util::TypeConstraints;
22d869ff 5
6our $VERSION = '0.01';
7our $AUTHORITY = 'cpan:STEVAN';
8
d26633fc 9extends 'MooseX::AttributeHelpers::Base';
10
11has '+method_constructors' => (
12 default => sub {
13 return +{
14 'get' => sub {
15 my $attr = shift;
16 return sub { $attr->get_value($_[0])->{$_[1]} };
17 },
18 'set' => sub {
19 my $attr = shift;
20 return sub { $attr->get_value($_[0])->{$_[1]} = $_[2] };
21 },
22 'count' => sub {
23 my $attr = shift;
24 return sub { scalar keys %{$attr->get_value($_[0])} };
25 },
26 'empty' => sub {
27 my $attr = shift;
28 return sub { scalar keys %{$attr->get_value($_[0])} ? 1 : 0 };
29 }
30 }
31 }
32);
33
34sub _process_options_for_provides {
35 my ($self, $options) = @_;
36 (exists $options->{isa})
37 || confess "You must define a type with the Hash metaclass";
38
88aaf2bd 39 (find_type_constraint($options->{isa})->is_a_type_of('HashRef'))
40 || confess "The type constraint for a Hash ($options->{isa}) must be a subtype of HashRef";
d26633fc 41}
42
43no Moose;
88aaf2bd 44no Moose::Util::TypeConstraints;
d26633fc 45
46# register the alias ...
47package Moose::Meta::Attribute::Custom::Collection::Hash;
48sub register_implementation { 'MooseX::AttributeHelpers::Collection::Hash' }
49
50
22d869ff 511;
52
53__END__
54
55=pod
56
57=head1 NAME
58
59=head1 SYNOPSIS
60
61=head1 DESCRIPTION
62
63=head1 METHODS
64
65=head1 BUGS
66
67All complex software has bugs lurking in it, and this module is no
68exception. If you find a bug please either email me, or add the bug
69to cpan-RT.
70
71=head1 AUTHOR
72
73Stevan Little E<lt>stevan@iinteractive.comE<gt>
74
75=head1 COPYRIGHT AND LICENSE
76
77Copyright 2007 by Infinity Interactive, Inc.
78
79L<http://www.iinteractive.com>
80
81This library is free software; you can redistribute it and/or modify
82it under the same terms as Perl itself.
83
84=cut