2 package Moose::Meta::Attribute::Native::Trait::Counter;
5 our $AUTHORITY = 'cpan:STEVAN';
7 with 'Moose::Meta::Attribute::Native::Trait' =>
8 { -excludes => ['_root_types'] };
10 sub _default_default { 0 }
11 sub _default_is { 'ro' }
12 sub _helper_type { 'Num' }
13 sub _root_types { 'Num', 'Int' }
19 # ABSTRACT: Helper trait for counters
31 traits => ['Counter'],
38 reset_counter => 'reset',
42 my $page = MyHomePage->new();
43 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
44 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
46 my $count_by_twos = 2;
47 $page->inc_counter($count_by_twos);
51 This trait provides native delegation methods for counters. A counter can be
52 any sort of number (integer or not). The delegation methods allow you to
53 increment, decrement, or reset the value.
57 If you don't provide an C<isa> value for your attribute, it will default to
60 =head1 PROVIDED METHODS
64 =item * B<set($value)>
66 Sets the counter to the specified value and returns the new value.
68 This method requires a single argument.
74 Increases the attribute value by the amount of the argument, or by 1 if no
75 argument is given. This method returns the new value.
77 This method accepts a single argument.
83 Decreases the attribute value by the amount of the argument, or by 1 if no
84 argument is given. This method returns the new value.
86 This method accepts a single argument.
90 Resets the value stored in this slot to its default value, and returns the new
97 See L<Moose/BUGS> for details on reporting bugs.