6ea512f4d76bf4f5802d1665602fc45261bacce9
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / MethodProvider / Bag.pm
1 package MooseX::AttributeHelpers::MethodProvider::Bag;
2 use Moose::Role;
3
4 our $VERSION   = '0.02';
5 our $AUTHORITY = 'cpan:STEVAN';
6
7 with 'MooseX::AttributeHelpers::MethodProvider::ImmutableHash';
8
9 sub add : method {
10     my ($attr, $reader, $writer) = @_;
11     return sub { $reader->($_[0])->{$_[1]}++ };
12 }
13
14 sub delete : method {
15     my ($attr, $reader, $writer) = @_;
16     return sub { CORE::delete $reader->($_[0])->{$_[1]} };
17 }
18
19 sub reset : method {
20     my ($attr, $reader, $writer) = @_;
21     return sub { $reader->($_[0])->{$_[1]} = 0 };
22 }
23
24 1;
25
26 __END__
27
28 =pod
29
30 =head1 NAME
31
32 MooseX::AttributeHelpers::MethodProvider::Bag
33
34 =head1 DESCRIPTION
35
36 This is a role which provides the method generators for
37 L<MooseX::AttributeHelpers::Collection::Bag>.  It also consumes 
38 L<MooseX::AttributeHelpers::Collection::ImmutableHash>, and thus provides all
39 of its methods asw well.
40
41 =head1 PROVIDED METHODS
42
43 =over 4
44
45 =item B<delete>
46
47 Remove the supplied key from the bag.
48
49 =item B<add>
50
51 Adds one to the value stored at the supplied key.
52
53 =item B<reset>
54
55 Sets the value at the supplied key to zero.
56
57 =back
58
59 =head1 BUGS
60
61 All complex software has bugs lurking in it, and this module is no
62 exception. If you find a bug please either email me, or add the bug
63 to cpan-RT.
64
65 =head1 AUTHOR
66
67 Stevan Little E<lt>stevan@iinteractive.comE<gt>
68
69 =head1 COPYRIGHT AND LICENSE
70
71 Copyright 2007-2008 by Infinity Interactive, Inc.
72
73 L<http://www.iinteractive.com>
74
75 This library is free software; you can redistribute it and/or modify
76 it under the same terms as Perl itself.
77
78 =cut
79