2 package Moose::Meta::Attribute::Native::Trait::Counter;
5 with 'Moose::Meta::Attribute::Native::Trait';
7 sub _default_default { 0 }
8 sub _default_is { 'ro' }
9 sub _helper_type { 'Num' }
10 sub _root_types { 'Num', 'Int' }
16 # ABSTRACT: Helper trait for Int attributes which represent counters
28 traits => ['Counter'],
35 reset_counter => 'reset',
39 my $page = MyHomePage->new();
40 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
41 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
43 my $count_by_twos = 2;
44 $page->inc_counter($count_by_twos);
48 This trait provides native delegation methods for counters. A counter can be
49 any sort of number (integer or not). The delegation methods allow you to
50 increment, decrement, or reset the value.
54 If you don't provide an C<isa> value for your attribute, it will default to
57 =head1 PROVIDED METHODS
61 =item * B<set($value)>
63 Sets the counter to the specified value and returns the new value.
65 This method requires a single argument.
71 Increases the attribute value by the amount of the argument, or by 1 if no
72 argument is given. This method returns the new value.
74 This method accepts a single argument.
80 Decreases the attribute value by the amount of the argument, or by 1 if no
81 argument is given. This method returns the new value.
83 This method accepts a single argument.
87 Resets the value stored in this slot to its default value, and returns the new
94 See L<Moose/BUGS> for details on reporting bugs.