package MooseX::AttributeHelpers::MethodProvider::Collection::Bag;
use MooseX::AttributeHelpers::MethodProvider;
use MooseX::AttributeHelpers::MethodProvider::Collection::ImmutableHash;
use Moose::Util::TypeConstraints;

our $VERSION   = '0.02';
our $AUTHORITY = 'cpan:STEVAN';

subtype 'Bag' => as 'HashRef[Int]';

add_method_provider 'Collection::Bag' => (
    type     => 'Bag',
    consumes => { 'Collection::ImmutableHash' => ':all' },
    provides => {
        add => sub {
            my ($attr, $reader, $writer) = @_;
            return sub { $reader->($_[0])->{$_[1]}++ };
        },

        delete => sub {
            my ($attr, $reader, $writer) = @_;
            return sub { CORE::delete $reader->($_[0])->{$_[1]} };
        },

        reset => sub {
            my ($attr, $reader, $writer) = @_;
            return sub { $reader->($_[0])->{$_[1]} = 0 };
        },
   },
);

1;

__END__

=pod

=head1 NAME

MooseX::AttributeHelpers::MethodProvider::Bag

=head1 DESCRIPTION

This is a role which provides the method generators for
L<MooseX::AttributeHelpers::Collection::Bag>.  It also consumes
L<MooseX::AttributeHelpers::Collection::ImmutableHash>, and thus provides all
of its methods asw well.

=head1 PROVIDED METHODS

=over 4

=item B<delete>

Remove the supplied key from the bag.

=item B<add>

Adds one to the value stored at the supplied key.

=item B<reset>

Sets the value at the supplied key to zero.

=back

=head1 BUGS

All complex software has bugs lurking in it, and this module is no
exception. If you find a bug please either email me, or add the bug
to cpan-RT.

=head1 AUTHOR

Stevan Little E<lt>stevan@iinteractive.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright 2007-2008 by Infinity Interactive, Inc.

L<http://www.iinteractive.com>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

