use Moose::AttributeHelpers::Trait::Collection::ImmutableHash;
use Moose::AttributeHelpers::Trait::Collection::Bag;
-use Moose::AttributeHelpers::Counter;
-use Moose::AttributeHelpers::Number;
-use Moose::AttributeHelpers::String;
-use Moose::AttributeHelpers::Bool;
-use Moose::AttributeHelpers::Collection::List;
-use Moose::AttributeHelpers::Collection::Array;
-use Moose::AttributeHelpers::Collection::Hash;
-use Moose::AttributeHelpers::Collection::ImmutableHash;
-use Moose::AttributeHelpers::Collection::Bag;
-
1;
__END__
use Moose::AttributeHelpers;
has 'mapping' => (
- metaclass => 'Collection::Hash',
+ traits => [ 'Collection::Hash' ],
is => 'rw',
isa => 'HashRef[Str]',
default => sub { {} },
+++ /dev/null
-package Moose::AttributeHelpers::Bool;
-use Moose;
-
-our $VERSION = '0.83';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
-extends 'Moose::Meta::Attribute';
-with 'Moose::AttributeHelpers::Trait::Bool';
-
-no Moose;
-
-# register the alias ...
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Bool;
-sub register_implementation { 'Moose::AttributeHelpers::Bool' }
-
-1;
-
-__END__
-
-=pod
-
-=head1 NAME
-
-Moose::AttributeHelpers::Bool
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=item B<method_provider>
-
-=item B<has_method_provider>
-
-=item B<helper_type>
-
-=item B<process_options_for_handles>
-
-Run before its superclass method.
-
-=item B<check_handles_values>
-
-Run after its superclass method.
-
-=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::Collection::Array;
-use Moose;
-
-our $VERSION = '0.83';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
-extends 'Moose::Meta::Attribute';
-with 'Moose::AttributeHelpers::Trait::Collection::Array';
-
-no Moose;
-
-# register the alias ...
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Collection::Array;
-sub register_implementation { 'Moose::AttributeHelpers::Collection::Array' }
-
-
-1;
-
-__END__
-
-=pod
-
-=head1 NAME
-
-Moose::AttributeHelpers::Collection::Array
-
-=head1 SYNOPSIS
-
- package Stuff;
- use Moose;
- use Moose::AttributeHelpers;
-
- has 'options' => (
- metaclass => 'Collection::Array',
- is => 'ro',
- isa => 'ArrayRef[Int]',
- default => sub { [] },
- handles => {
- add_options => 'push',
- remove_last_option => 'pop',
- }
- );
-
-=head1 DESCRIPTION
-
-This module provides an Array attribute which provides a number of
-array operations. See L<Moose::AttributeHelpers::MethodProvider::Array>
-for more details.
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=item B<method_provider>
-
-=item B<has_method_provider>
-
-=item B<helper_type>
-
-=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::Collection::Bag;
-use Moose;
-
-our $VERSION = '0.83';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
-extends 'Moose::Meta::Attribute';
-with 'Moose::AttributeHelpers::Trait::Collection::Bag';
-
-no Moose;
-
-# register the alias ...
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Collection::Bag;
-sub register_implementation { 'Moose::AttributeHelpers::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>
-
-=item B<helper_type>
-
-=item B<process_options_for_handles>
-
-=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::Collection::Hash;
-use Moose;
-
-our $VERSION = '0.83';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
-extends 'Moose::Meta::Attribute';
-with 'Moose::AttributeHelpers::Trait::Collection::Hash';
-
-no Moose;
-
-# register the alias ...
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Collection::Hash;
-sub register_implementation { 'Moose::AttributeHelpers::Collection::Hash' }
-
-
-1;
-
-__END__
-
-=pod
-
-=head1 NAME
-
-Moose::AttributeHelpers::Collection::Hash
-
-=head1 SYNOPSIS
-
- package Stuff;
- use Moose;
- use Moose::AttributeHelpers;
-
- has 'options' => (
- metaclass => 'Collection::Hash',
- is => 'ro',
- isa => 'HashRef[Str]',
- default => sub { {} },
- handles => {
- set_option => 'set',
- get_option => 'get',
- has_options => 'empty',
- num_options => 'count',
- delete_option => 'delete',
- }
- );
-
-=head1 DESCRIPTION
-
-This module provides a Hash attribute which provides a number of
-hash-like operations. See L<Moose::AttributeHelpers::MethodProvider::Hash>
-for more details.
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=item B<method_provider>
-
-=item B<has_method_provider>
-
-=item B<helper_type>
-
-=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::Collection::ImmutableHash;
-use Moose;
-
-our $VERSION = '0.83';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
-extends 'Moose::Meta::Attribute';
-with 'Moose::AttributeHelpers::Trait::Collection::ImmutableHash';
-
-no Moose;
-
-# register the alias ...
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Collection::ImmutableHash;
-sub register_implementation { 'Moose::AttributeHelpers::Collection::ImmutableHash' }
-
-
-1;
-
-__END__
-
-=pod
-
-=head1 NAME
-
-Moose::AttributeHelpers::Collection::ImmutableHash
-
-=head1 SYNOPSIS
-
- package Stuff;
- use Moose;
- use Moose::AttributeHelpers;
-
- has 'options' => (
- metaclass => 'Collection::ImmutableHash',
- is => 'ro',
- isa => 'HashRef[Str]',
- default => sub { {} },
- handles => {
- get_option => 'get',
- has_options => 'empty',
- get_option_list => 'keys',
- }
- );
-
-=head1 DESCRIPTION
-
-This module provides a immutable HashRef attribute which provides a number of
-hash-line operations. See L<Moose::AttributeHelpers::MethodProvider::ImmutableHash>
-for more details.
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=item B<method_provider>
-
-=item B<has_method_provider>
-
-=item B<helper_type>
-
-=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::Collection::List;
-use Moose;
-
-our $VERSION = '0.83';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
-extends 'Moose::Meta::Attribute';
-with 'Moose::AttributeHelpers::Trait::Collection::List';
-
-no Moose;
-
-# register the alias ...
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Collection::List;
-sub register_implementation { 'Moose::AttributeHelpers::Collection::List' }
-
-
-1;
-
-__END__
-
-=pod
-
-=head1 NAME
-
-Moose::AttributeHelpers::Collection::List
-
-=head1 SYNOPSIS
-
- package Stuff;
- use Moose;
- use Moose::AttributeHelpers;
-
- has 'options' => (
- metaclass => 'Collection::List',
- is => 'ro',
- isa => 'ArrayRef[Int]',
- default => sub { [] },
- handles => {
- map_options => 'map',
- filter_options => 'grep',
- }
- );
-
-=head1 DESCRIPTION
-
-This module provides an List attribute which provides a number of
-list operations. See L<Moose::AttributeHelpers::MethodProvider::List>
-for more details.
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=item B<method_provider>
-
-=item B<has_method_provider>
-
-=item B<helper_type>
-
-=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::Counter;
-use Moose;
-
-our $VERSION = '0.83';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
-extends 'Moose::Meta::Attribute';
-with 'Moose::AttributeHelpers::Trait::Counter';
-
-no Moose;
-
-# register the alias ...
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Counter;
-sub register_implementation { 'Moose::AttributeHelpers::Counter' }
-
-1;
-
-__END__
-
-=pod
-
-=head1 NAME
-
-Moose::AttributeHelpers::Counter
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=item B<method_provider>
-
-=item B<has_method_provider>
-
-=item B<helper_type>
-
-=item B<process_options_for_handles>
-
-Run before its superclass method.
-
-=item B<check_handles_values>
-
-Run after its superclass method.
-
-=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::Number;
-use Moose;
-
-our $VERSION = '0.83';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
-extends 'Moose::Meta::Attribute';
-with 'Moose::AttributeHelpers::Trait::Number';
-
-no Moose;
-
-# register the alias ...
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Number;
-sub register_implementation { 'Moose::AttributeHelpers::Number' }
-
-1;
-
-=pod
-
-=head1 NAME
-
-Moose::AttributeHelpers::Number
-
-=head1 SYNOPSIS
-
- package Real;
- use Moose;
- use Moose::AttributeHelpers;
-
- has 'integer' => (
- metaclass => 'Number',
- is => 'ro',
- isa => 'Int',
- default => sub { 5 },
- handles => {
- set => 'set',
- add => 'add',
- sub => 'sub',
- mul => 'mul',
- div => 'div',
- mod => 'mod',
- abs => 'abs',
- }
- );
-
- my $real = Real->new();
- $real->add(5); # same as $real->integer($real->integer + 5);
- $real->sub(2); # same as $real->integer($real->integer - 2);
-
-=head1 DESCRIPTION
-
-This provides a simple numeric attribute, which supports most of the
-basic math operations.
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=item B<helper_type>
-
-=item B<method_constructors>
-
-=back
-
-=head1 PROVIDED METHODS
-
-It is important to note that all those methods do in place
-modification of the value stored in the attribute.
-
-=over 4
-
-=item I<set ($value)>
-
-Alternate way to set the value.
-
-=item I<add ($value)>
-
-Adds the current value of the attribute to C<$value>.
-
-=item I<sub ($value)>
-
-Subtracts the current value of the attribute to C<$value>.
-
-=item I<mul ($value)>
-
-Multiplies the current value of the attribute to C<$value>.
-
-=item I<div ($value)>
-
-Divides the current value of the attribute to C<$value>.
-
-=item I<mod ($value)>
-
-Modulus the current value of the attribute to C<$value>.
-
-=item I<abs>
-
-Sets the current value of the attribute to its absolute value.
-
-=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
-
-Robert Boone
-
-=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::String;
-use Moose;
-
-our $VERSION = '0.83';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
-extends 'Moose::Meta::Attribute';
-with 'Moose::AttributeHelpers::Trait::String';
-
-no Moose;
-
-# register the alias ...
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::String;
-sub register_implementation { 'Moose::AttributeHelpers::String' }
-
-1;
-
-__END__
-
-=pod
-
-=head1 NAME
-
-Moose::AttributeHelpers::String
-
-=head1 SYNOPSIS
-
- package MyHomePage;
- use Moose;
- use Moose::AttributeHelpers;
-
- has 'text' => (
- metaclass => 'String',
- is => 'rw',
- isa => 'Str',
- default => sub { '' },
- handles => {
- "add_text" => "append",
- "replace_text" => "replace",
- }
- );
-
- my $page = MyHomePage->new();
- $page->add_text("foo"); # same as $page->text($page->text . "foo");
-
-=head1 DESCRIPTION
-
-This module provides a simple string attribute, to which mutating string
-operations can be applied more easily (no need to make an lvalue attribute
-metaclass or use temporary variables). Additional methods are provided for
-completion.
-
-If your attribute definition does not include any of I<is>, I<isa>, I<default>
-or I<handles> but does use the C<String> metaclass, then this module applies
-defaults as in the L</SYNOPSIS> above. This allows for a very basic counter
-definition:
-
- has 'foo' => (metaclass => 'String');
- $obj->append_foo;
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=item B<method_provider>
-
-=item B<has_method_provider>
-
-=item B<helper_type>
-
-=item B<process_options_for_handles>
-
-Run before its superclass method.
-
-=item B<check_handles_values>
-
-Run after its superclass method.
-
-=back
-
-=head1 PROVIDED METHODS
-
-It is important to note that all those methods do in place
-modification of the value stored in the attribute.
-
-=over 4
-
-=item I<inc>
-
-Increments the value stored in this slot using the magical string autoincrement
-operator. Note that Perl doesn't provide analogous behavior in C<-->, so
-C<dec> is not available.
-
-=item I<append> C<$string>
-
-Append a string, like C<.=>.
-
-=item I<prepend> C<$string>
-
-Prepend a string.
-
-=item I<replace> C<$pattern> C<$replacement>
-
-Performs a regexp substitution (L<perlop/s>). There is no way to provide the
-C<g> flag, but code references will be accepted for the replacement, causing
-the regex to be modified with a single C<e>. C</smxi> can be applied using the
-C<qr> operator.
-
-=item I<match> C<$pattern>
-
-Like I<replace> but without the replacement. Provided mostly for completeness.
-
-=item C<chop>
-
-L<perlfunc/chop>
-
-=item C<chomp>
-
-L<perlfunc/chomp>
-
-=item C<clear>
-
-Sets the string to the empty string (not the value passed to C<default>).
-
-=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
use Moose::Role;
has 'options' => (
- metaclass => 'Collection::Array',
+ traits => [ 'Collection::Array' ],
is => 'ro',
isa => 'ArrayRef[Foo]',
);
use Moose::Role;
has 'stuff' => (
- metaclass => 'Collection::Array',
+ traits => [ 'Collection::Array' ],
is => 'ro',
isa => 'ArrayRef',
- provides => {
- 'get' => 'get_stuff'
+ handles => {
+ get_stuff => 'get',
}
);
'dec_counter' => 'dec',
'reset_counter' => 'reset',
'set_counter' => 'set',
-}, '... got the right default provides methods');
+}, '... got the right default handles methods');
use Moose;
has 'counter' => (
- metaclass => 'Counter',
+ traits => [ 'Counter' ],
is => 'ro',
isa => 'Int',
default => sub { 0 },
- provides => {
- inc => 'inc_counter',
- dec => 'dec_counter',
- reset => 'reset_counter',
+ handles => {
+ inc_counter => 'inc',
+ dec_counter => 'dec',
+ reset_counter => 'reset',
}
);
}
exclaim => [ append => [ '!' ] ],
capitalize_last => [ replace => [ qr/(.)$/, $uc ] ],
invalid_number => [ match => [ qr/\D/ ] ],
-}, '... got the right provides methods');
+}, '... got the right handles methods');