Docs tentatively finished.
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / MethodProvider / Collection / Bag.pm
1 package MooseX::AttributeHelpers::MethodProvider::Collection::Bag;
2 use MooseX::AttributeHelpers::MethodProvider;
3 use MooseX::AttributeHelpers::MethodProvider::Collection::ImmutableHash;
4 use Moose::Util::TypeConstraints;
5
6 our $VERSION   = '0.02';
7 our $AUTHORITY = 'cpan:STEVAN';
8
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 );
31
32 1;
33
34 __END__
35
36 =pod
37
38 =head1 NAME
39
40 MooseX::AttributeHelpers::MethodProvider::Bag
41
42 =head1 DESCRIPTION
43
44 This module provides the method factories for
45 L<MooseX::AttributeHelpers::Collection::Bag>.  It also consumes
46 L<MooseX::AttributeHelpers::MethodProvider::Collection::ImmutableHash>, 
47 and thus provides all of its methods as well.
48
49 =head1 PROVIDED METHODS
50
51 =over 4
52
53 =item B<delete>
54
55 Remove the supplied key from the bag.
56
57 =item B<add>
58
59 Adds one to the value stored at the supplied key.
60
61 =item B<reset>
62
63 Sets the value at the supplied key to zero.
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
79 Copyright 2007-2008 by Infinity Interactive, Inc.
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