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