use Moose::AttributeHelpers::Trait::Collection::Array;
use Moose::AttributeHelpers::Trait::Collection::Hash;
use Moose::AttributeHelpers::Trait::Collection::ImmutableHash;
-use Moose::AttributeHelpers::Trait::Collection::Bag;
1;
+++ /dev/null
-package Moose::AttributeHelpers::MethodProvider::Bag;
-use Moose::Role;
-
-our $VERSION = '0.87';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
-with 'Moose::AttributeHelpers::MethodProvider::ImmutableHash';
-
-sub add : method {
- my ( $attr, $reader, $writer ) = @_;
- return sub { $reader->( $_[0] )->{ $_[1] }++ };
-}
-
-sub delete : method {
- my ( $attr, $reader, $writer ) = @_;
- return sub { CORE::delete $reader->( $_[0] )->{ $_[1] } };
-}
-
-sub reset : method {
- my ( $attr, $reader, $writer ) = @_;
- return sub { $reader->( $_[0] )->{ $_[1] } = 0 };
-}
-
-1;
-
-__END__
-
-=pod
-
-=head1 NAME
-
-Moose::AttributeHelpers::MethodProvider::Bag
-
-=head1 DESCRIPTION
-
-This is a role which provides the method generators for
-L<Moose::AttributeHelpers::Collection::Bag>.
-
-This role is composed from the
-L<Moose::AttributeHelpers::Collection::ImmutableHash> role.
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=back
-
-=head1 PROVIDED METHODS
-
-=over 4
-
-=item B<count>
-
-=item B<delete>
-
-=item B<empty>
-
-=item B<exists>
-
-=item B<get>
-
-=item B<keys>
-
-=item B<add>
-
-=item B<reset>
-
-=item B<values>
-
-=item B<kv>
-
-=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-2009 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
-
+++ /dev/null
-
-package Moose::AttributeHelpers::Trait::Collection::Bag;
-use Moose::Role;
-use Moose::Util::TypeConstraints;
-
-our $VERSION = '0.87';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
-use Moose::AttributeHelpers::MethodProvider::Bag;
-
-with 'Moose::AttributeHelpers::Trait::Collection';
-
-has 'method_provider' => (
- is => 'ro',
- isa => 'ClassName',
- predicate => 'has_method_provider',
- default => 'Moose::AttributeHelpers::MethodProvider::Bag'
-);
-
-subtype 'Bag' => as 'HashRef[Int]';
-
-sub _helper_type { 'Bag' }
-
-sub _default_default { sub { {} } }
-
-no Moose::Role;
-no Moose::Util::TypeConstraints;
-
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Trait::Collection::Bag;
-sub register_implementation {
- 'Moose::AttributeHelpers::Trait::Collection::Bag'
-}
-
-1;
-
-__END__
-
-=pod
-
-=head1 NAME
-
-Moose::AttributeHelpers::Collection::Bag
-
-=head1 SYNOPSIS
-
- package Stuff;
- use Moose;
- use Moose::AttributeHelpers;
-
- has 'word_histogram' => (
- metaclass => 'Collection::Bag',
- is => 'ro',
- isa => 'Bag', # optional ... as is defalt
- handles => {
- add_word => 'add',
- get_count_for => 'get',
- has_any_words => 'empty',
- num_words => 'count',
- delete_word => 'delete',
- }
- );
-
-=head1 DESCRIPTION
-
-This module provides a Bag attribute which provides a number of
-bag-like operations. See L<Moose::AttributeHelpers::MethodProvider::Bag>
-for more details.
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=item B<method_provider>
-
-=item B<has_method_provider>
-
-=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-2009 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
+++ /dev/null
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-
-use Test::More tests => 19;
-use Test::Exception;
-use Test::Moose 'does_ok';
-
-{
-
- package Stuff;
- use Moose;
- use Moose::AttributeHelpers;
-
- has 'word_histogram' => (
- traits => ['Collection::Bag'],
- is => 'ro',
- handles => {
- 'add_word' => 'add',
- 'get_count_for' => 'get',
- 'has_any_words' => 'empty',
- 'num_words' => 'count',
- 'delete_word' => 'delete',
- }
- );
-}
-
-my $stuff = Stuff->new();
-isa_ok( $stuff, 'Stuff' );
-
-can_ok( $stuff, $_ ) for qw[
- add_word
- get_count_for
- has_any_words
- num_words
- delete_word
-];
-
-ok( !$stuff->has_any_words, '... we have no words' );
-is( $stuff->num_words, 0, '... we have no words' );
-
-lives_ok {
- $stuff->add_word('bar');
-}
-'... set the words okay';
-
-ok( $stuff->has_any_words, '... we have words' );
-is( $stuff->num_words, 1, '... we have 1 word(s)' );
-is( $stuff->get_count_for('bar'), 1, '... got words now' );
-
-lives_ok {
- $stuff->add_word('foo');
- $stuff->add_word('bar') for 0 .. 3;
- $stuff->add_word('baz') for 0 .. 10;
-}
-'... set the words okay';
-
-is( $stuff->num_words, 3, '... we still have 1 word(s)' );
-is( $stuff->get_count_for('foo'), 1, '... got words now' );
-is( $stuff->get_count_for('bar'), 5, '... got words now' );
-is( $stuff->get_count_for('baz'), 11, '... got words now' );
-
-## test the meta
-
-my $words = $stuff->meta->get_attribute('word_histogram');
-does_ok( $words, 'Moose::AttributeHelpers::Trait::Collection::Bag' );
-
-is_deeply(
- $words->handles,
- {
- 'add_word' => 'add',
- 'get_count_for' => 'get',
- 'has_any_words' => 'empty',
- 'num_words' => 'count',
- 'delete_word' => 'delete',
- },
- '... got the right handles mapping'
-);
-