2 package Moose::Meta::Attribute::Native::Trait::Counter;
5 with 'Moose::Meta::Attribute::Native::Trait' =>
6 { -excludes => ['_root_types'] };
8 sub _default_default { 0 }
9 sub _default_is { 'ro' }
10 sub _helper_type { 'Num' }
11 sub _root_types { 'Num', 'Int' }
17 # ABSTRACT: Helper trait for Int attributes which represent counters
29 traits => ['Counter'],
36 reset_counter => 'reset',
40 my $page = MyHomePage->new();
41 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
42 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
44 my $count_by_twos = 2;
45 $page->inc_counter($count_by_twos);
49 This trait provides native delegation methods for counters. A counter can be
50 any sort of number (integer or not). The delegation methods allow you to
51 increment, decrement, or reset the value.
55 If you don't provide an C<isa> value for your attribute, it will default to
58 =head1 PROVIDED METHODS
62 =item * B<set($value)>
64 Sets the counter to the specified value and returns the new value.
66 This method requires a single argument.
72 Increases the attribute value by the amount of the argument, or by 1 if no
73 argument is given. This method returns the new value.
75 This method accepts a single argument.
81 Decreases the attribute value by the amount of the argument, or by 1 if no
82 argument is given. This method returns the new value.
84 This method accepts a single argument.
88 Resets the value stored in this slot to its default value, and returns the new
95 See L<Moose/BUGS> for details on reporting bugs.