package Moose::Meta::Attribute::Native::Trait::Counter;
use Moose::Role;
-our $VERSION = '0.87';
+our $VERSION = '0.95';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
sub _default_is { 'ro' }
sub _helper_type { 'Num' }
-after '_check_handles_values' => sub {
- my $self = shift;
- my $handles = $self->handles;
-
- unless ( scalar keys %$handles ) {
- my $method_constructors = $self->method_constructors;
- my $attr_name = $self->name;
-
- foreach my $method ( keys %$method_constructors ) {
- $handles->{ $method . '_' . $attr_name } = $method;
- }
-
- $self->_set_handles($handles);
- }
-};
-
no Moose::Role;
1;
=head1 NAME
-Moose::Meta::Attribute::Native::Trait::Counter
+Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for counters
=head1 SYNOPSIS
package MyHomePage;
use Moose;
- use Moose::AttributeHelpers;
has 'counter' => (
- metaclass => 'Counter',
+ traits => ['Counter'],
is => 'ro',
isa => 'Num',
default => 0,
inc_counter => 'inc',
dec_counter => 'dec',
reset_counter => 'reset',
- }
+ },
);
my $page = MyHomePage->new();
incremented and decremented.
If your attribute definition does not include any of I<is>, I<isa>,
-I<default> or I<handles> but does use the C<Counter> metaclass,
+I<default> or I<handles> but does use the C<Counter> trait,
then this module applies defaults as in the L</SYNOPSIS>
above. This allows for a very basic counter definition:
- has 'foo' => (metaclass => 'Counter');
+ has 'foo' => (traits => ['Counter']);
$obj->inc_foo;
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=item B<method_provider>
-
-=item B<has_method_provider>
-
-=back
-
=head1 PROVIDED METHODS
-It is important to note that all those methods do in place
-modification of the value stored in the attribute.
+These methods are implemented in
+L<Moose::Meta::Attribute::Native::MethodProvider::Counter>. 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>
+=item B<set($value)>
Set the counter to the specified value.
-=item I<inc>
+=item B<inc>
Increments the value stored in this slot by 1. Providing an argument will
cause the counter to be increased by specified amount.
-=item I<dec>
+=item B<dec>
Decrements the value stored in this slot by 1. Providing an argument will
cause the counter to be increased by specified amount.
-=item I<reset>
+=item B<reset>
Resets the value stored in this slot to it's default value.
=back
+=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.
+See L<Moose/BUGS> for details on reporting bugs.
=head1 AUTHOR