Lots of files got moved around,a nd some got added.
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / MethodProvider / Collection / Bag.pm
CommitLineData
1b45ecc4 1package MooseX::AttributeHelpers::MethodProvider::Collection::Bag;
2use MooseX::AttributeHelpers::MethodProvider;
3use MooseX::AttributeHelpers::MethodProvider::Collection::ImmutableHash;
4use Moose::Util::TypeConstraints;
9a976497 5
6our $VERSION = '0.02';
7our $AUTHORITY = 'cpan:STEVAN';
8
1b45ecc4 9subtype 'Bag' => as 'HashRef[Int]';
10
11add_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
321;
33
34__END__
35
36=pod
37
38=head1 NAME
39
40MooseX::AttributeHelpers::MethodProvider::Bag
41
42=head1 DESCRIPTION
43
44This is a role which provides the method generators for
1b45ecc4 45L<MooseX::AttributeHelpers::Collection::Bag>. It also consumes
720fa35b 46L<MooseX::AttributeHelpers::Collection::ImmutableHash>, and thus provides all
47of its methods asw well.
9a976497 48
49=head1 PROVIDED METHODS
50
51=over 4
52
9a976497 53=item B<delete>
54
720fa35b 55Remove the supplied key from the bag.
9a976497 56
57=item B<add>
58
720fa35b 59Adds one to the value stored at the supplied key.
9a976497 60
720fa35b 61=item B<reset>
9a976497 62
720fa35b 63Sets the value at the supplied key to zero.
9a976497 64
65=back
66
67=head1 BUGS
68
69All complex software has bugs lurking in it, and this module is no
70exception. If you find a bug please either email me, or add the bug
71to cpan-RT.
72
73=head1 AUTHOR
74
75Stevan Little E<lt>stevan@iinteractive.comE<gt>
76
77=head1 COPYRIGHT AND LICENSE
78
99c62fb8 79Copyright 2007-2008 by Infinity Interactive, Inc.
9a976497 80
81L<http://www.iinteractive.com>
82
83This library is free software; you can redistribute it and/or modify
84it under the same terms as Perl itself.
85
86=cut
87