X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FAttribute%2FNative%2FTrait%2FCounter.pm;h=a61b968baacab37bdedac41e46a25054711a78cc;hb=ae7820b1b884344a7ee90d94b484ca46459eb7b1;hp=54a0adfd4bb0b481e04e32a034a96a3a51cf9c5c;hpb=9610c1d2be5ceb367ec30633643d6d9bce82bfe0;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Attribute/Native/Trait/Counter.pm b/lib/Moose/Meta/Attribute/Native/Trait/Counter.pm index 54a0adf..a61b968 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait/Counter.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait/Counter.pm @@ -2,7 +2,7 @@ package Moose::Meta::Attribute::Native::Trait::Counter; use Moose::Role; -our $VERSION = '0.89'; +our $VERSION = '1.06'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -21,22 +21,6 @@ sub _default_default { 0 } 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; @@ -47,7 +31,7 @@ __END__ =head1 NAME -Moose::Meta::Attribute::Native::Trait::Counter +Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for counters =head1 SYNOPSIS @@ -69,19 +53,15 @@ Moose::Meta::Attribute::Native::Trait::Counter my $page = MyHomePage->new(); $page->inc_counter; # same as $page->counter( $page->counter + 1 ); $page->dec_counter; # same as $page->counter( $page->counter - 1 ); + + my $count_by_twos = 2; + $page->inc_counter($count_by_twos); =head1 DESCRIPTION This module provides a simple counter attribute, which can be -incremented and decremented. - -If your attribute definition does not include any of I, I, -I or I but does use the C trait, -then this module applies defaults as in the L -above. This allows for a very basic counter definition: - - has 'foo' => (traits => ['Counter']); - $obj->inc_foo; +incremented and decremented by arbitrary amounts. The default +amount of change is one. =head1 PROVIDED METHODS @@ -92,21 +72,21 @@ the attribute. =over 4 -=item I +=item B Set the counter to the specified value. -=item I +=item B -Increments the value stored in this slot by 1. Providing an argument will -cause the counter to be increased by specified amount. +Increase the attribute value by the amount of the argument. +No argument increments the value by 1. -=item I +=item B -Decrements the value stored in this slot by 1. Providing an argument will -cause the counter to be increased by specified amount. +Decrease the attribute value by the amount of the argument. +No argument decrements the value by 1. -=item I +=item B Resets the value stored in this slot to it's default value. @@ -126,9 +106,7 @@ Resets the value stored in this slot to it's default value. =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 for details on reporting bugs. =head1 AUTHOR