Commit | Line | Data |
9a976497 |
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 |
720fa35b |
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. |
9a976497 |
40 | |
41 | =head1 PROVIDED METHODS |
42 | |
43 | =over 4 |
44 | |
9a976497 |
45 | =item B<delete> |
46 | |
720fa35b |
47 | Remove the supplied key from the bag. |
9a976497 |
48 | |
49 | =item B<add> |
50 | |
720fa35b |
51 | Adds one to the value stored at the supplied key. |
9a976497 |
52 | |
720fa35b |
53 | =item B<reset> |
9a976497 |
54 | |
720fa35b |
55 | Sets the value at the supplied key to zero. |
9a976497 |
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 | |
99c62fb8 |
71 | Copyright 2007-2008 by Infinity Interactive, Inc. |
9a976497 |
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 | |