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