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