used attribute helper methods for more specific types of data.
As seen in the L</SYNOPSIS>, you specify the extension via the
-C<metaclass> parameter. Available meta classes are:
+C<trait> parameter. Available meta classes are below; see L</METHOD PROVIDERS>.
=head1 PARAMETERS
=head2 handles
-This points to a hashref that uses C<method> for the keys and
-C<stuff> for the values. The method will be added to
-the object itself and do what you want.
-
-=head2 curries
-
-This points to a hashref that uses C<provider> for the keys and
-has two choices for the value:
-
-You can supply C<< {method => [ @args ]} >> for the values. The method will be
-added to the object itself (always using C<@args> as the beginning arguments).
-
-Another approach to curry a method provider is to supply a coderef instead of an
-arrayref. The code ref takes C<$self>, C<$body>, and any additional arguments
-passed to the final method.
-
- # ...
-
- curries => {
- grep => {
- times_with_day => sub {
- my ($self, $body, $datetime) = @_;
- $body->($self, sub { $_->ymd eq $datetime->ymd });
- }
- }
- }
-
- # ...
-
- $obj->times_with_day(DateTime->now); # takes datetime argument, checks day
-
+This is like C<< handles >> in L<Moose/has>, but only HASH references are
+allowed. Keys are method names that you want installed locally, and values are
+methods from the method providers (below). Currying with delegated methods works normally for C<< handles >>.
=head1 METHOD PROVIDERS
=over
-=item L<Number|Moose::AttributeHelpers::Number>
+=item L<Number|Moose::AttributeHelpers::Trait::Number>
Common numerical operations.
-=item L<String|Moose::AttributeHelpers::String>
+=item L<String|Moose::AttributeHelpers::Trait::String>
Common methods for string operations.
-=item L<Counter|Moose::AttributeHelpers::Counter>
+=item L<Counter|Moose::AttributeHelpers::Trait::Counter>
Methods for incrementing and decrementing a counter attribute.
-=item L<Bool|Moose::AttributeHelpers::Bool>
+=item L<Bool|Moose::AttributeHelpers::Trait::Bool>
Common methods for boolean values.
-=item L<Collection::Hash|Moose::AttributeHelpers::Collection::Hash>
+=item L<Collection::Hash|Moose::AttributeHelpers::Trait::Collection::Hash>
Common methods for hash references.
-=item L<Collection::ImmutableHash|Moose::AttributeHelpers::Collection::ImmutableHash>
+=item L<Collection::ImmutableHash|Moose::AttributeHelpers::Trait::Collection::ImmutableHash>
Common methods for inspecting hash references.
-=item L<Collection::Array|Moose::AttributeHelpers::Collection::Array>
+=item L<Collection::Array|Moose::AttributeHelpers::Trait::Collection::Array>
Common methods for array references.
-=item L<Collection::List|Moose::AttributeHelpers::Collection::List>
+=item L<Collection::List|Moose::AttributeHelpers::Trait::Collection::List>
Common list methods for array references.
is => 'ro',
isa => 'ArrayRef[Int]',
default => sub { [] },
- provides => {
- 'push' => 'add_options',
- 'pop' => 'remove_last_option',
+ handles => {
+ add_options => 'push',
+ remove_last_option => 'pop',
}
);
metaclass => 'Collection::Bag',
is => 'ro',
isa => 'Bag', # optional ... as is defalt
- provides => {
- 'add' => 'add_word',
- 'get' => 'get_count_for',
- 'empty' => 'has_any_words',
- 'count' => 'num_words',
- 'delete' => 'delete_word',
+ handles => {
+ add_word => 'add',
+ get_count_for => 'get',
+ has_any_words => 'empty',
+ num_words => 'count',
+ delete_word => 'delete',
}
);
is => 'ro',
isa => 'HashRef[Str]',
default => sub { {} },
- provides => {
- 'set' => 'set_option',
- 'get' => 'get_option',
- 'empty' => 'has_options',
- 'count' => 'num_options',
- 'delete' => 'delete_option',
+ handles => {
+ set_option => 'set',
+ get_option => 'get',
+ has_options => 'empty',
+ num_options => 'count',
+ delete_option => 'delete',
}
);
is => 'ro',
isa => 'HashRef[Str]',
default => sub { {} },
- provides => {
- 'get' => 'get_option',
- 'empty' => 'has_options',
- 'keys' => 'get_option_list',
+ handles => {
+ get_option => 'get',
+ has_options => 'empty',
+ get_option_list => 'keys',
}
);
is => 'ro',
isa => 'ArrayRef[Int]',
default => sub { [] },
- provides => {
- map => 'map_options',
- grep => 'filter_options',
+ handles => {
+ map_options => 'map',
+ filter_options => 'grep',
}
);
isa => 'ArrayRef[Str]',
default => sub { [] },
auto_deref => 1,
- provides => {
- elements => 'all_options',
- map => 'map_options',
- grep => 'filter_options',
- find => 'find_option',
- first => 'first_option',
- last => 'last_option',
- get => 'get_option',
- join => 'join_options',
- count => 'count_options',
- empty => 'do_i_have_options',
- sort => 'sorted_options',
+ handles => {
+ all_options => 'elements',
+ map_options => 'map',
+ filter_options => 'grep',
+ find_option => 'find',
+ first_option => 'first',
+ last_option => 'last',
+ get_option => 'get',
+ join_options => 'join',
+ count_options => 'count',
+ do_i_have_options => 'empty',
+ sorted_options => 'sort',
}
);
is => 'ro',
isa => 'Int',
default => sub { 5 },
- provides => {
+ handles => {
set => 'set',
add => 'add',
sub => 'sub',
is => 'rw',
isa => 'Str',
default => sub { '' },
- provides => {
- append => "add_text",
- replace => "replace_text",
+ handles => {
+ "add_text" => "append",
+ "replace_text" => "replace",
}
);
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<provides> 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:
+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;
is => 'rw',
isa => 'Bool',
default => sub { 0 },
- provides => {
- set => 'illuminate',
- unset => 'darken',
- toggle => 'flip_switch',
- not => 'is_dark'
+ handles => {
+ illuminate => 'set',
+ darken => 'unset',
+ flip_switch => 'toggle',
+ is_dark => 'not',
}
);
is => 'ro',
isa => 'ArrayRef[Int]',
default => sub { [] },
- provides => {
- 'push' => 'add_options',
- 'pop' => 'remove_last_option',
+ handles => {
+ add_options => 'push',
+ remove_last_option => 'pop',
}
);
metaclass => 'Collection::Bag',
is => 'ro',
isa => 'Bag', # optional ... as is defalt
- provides => {
- 'add' => 'add_word',
- 'get' => 'get_count_for',
- 'empty' => 'has_any_words',
- 'count' => 'num_words',
- 'delete' => 'delete_word',
+ handles => {
+ add_word => 'add',
+ get_count_for => 'get',
+ has_any_words => 'empty',
+ num_words => 'count',
+ delete_word => 'delete',
}
);
is => 'ro',
isa => 'HashRef[Str]',
default => sub { {} },
- provides => {
- 'set' => 'set_option',
- 'get' => 'get_option',
- 'empty' => 'has_options',
- 'count' => 'num_options',
- 'delete' => 'delete_option',
+ handles => {
+ set_option => 'set',
+ get_option => 'get',
+ has_options => 'empty',
+ num_options => 'count',
+ delete_option => 'delete',
}
);
is => 'ro',
isa => 'HashRef[Str]',
default => sub { {} },
- provides => {
- 'get' => 'get_option',
- 'empty' => 'has_options',
- 'keys' => 'get_option_list',
+ handles => {
+ get_option => 'get',
+ has_options => 'empty',
+ get_option_list => 'keys',
}
);
is => 'ro',
isa => 'ArrayRef[Int]',
default => sub { [] },
- provides => {
- map => 'map_options',
- grep => 'filter_options',
+ handles => {
+ map_options => 'map',
+ filter_options => 'grep',
}
);
is => 'ro',
isa => 'Num',
default => sub { 0 },
- provides => {
- inc => 'inc_counter',
- dec => 'dec_counter',
- reset => 'reset_counter',
+ handles => {
+ inc_counter => 'inc',
+ dec_counter => 'dec',
+ reset_counter => 'reset',
}
);
incremented and decremented.
If your attribute definition does not include any of I<is>, I<isa>,
-I<default> or I<provides> but does use the C<Counter> metaclass,
+I<default> or I<handles> but does use the C<Counter> metaclass,
then this module applies defaults as in the L</SYNOPSIS>
above. This allows for a very basic counter definition:
is => 'ro',
isa => 'Int',
default => sub { 5 },
- provides => {
+ handles => {
set => 'set',
add => 'add',
sub => 'sub',
is => 'rw',
isa => 'Str',
default => sub { '' },
- provides => {
- append => "add_text",
- replace => "replace_text",
+ handles => {
+ add_text => 'append',
+ replace_text => 'replace',
}
);
completion.
If your attribute definition does not include any of I<is>, I<isa>,
-I<default> or I<provides> but does use the C<String> metaclass,
+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: