2 package Moose::Meta::Attribute::Native::Trait::Counter;
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 with 'Moose::Meta::Attribute::Native::Trait' =>
10 { -excludes => ['_root_types'] };
12 sub _default_default { 0 }
13 sub _default_is { 'ro' }
14 sub _helper_type { 'Num' }
15 sub _root_types { 'Num', 'Int' }
27 Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for counters
35 traits => ['Counter'],
42 reset_counter => 'reset',
46 my $page = MyHomePage->new();
47 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
48 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
50 my $count_by_twos = 2;
51 $page->inc_counter($count_by_twos);
55 This trait provides native delegation methods for counters. A counter can be
56 any sort of number (integer or not). The delegation methods allow you to
57 increment, decrement, or reset the value.
61 If you don't provide an C<isa> value for your attribute, it will default to
64 =head1 PROVIDED METHODS
68 =item * B<set($value)>
70 Sets the counter to the specified value and returns the new value.
72 This method requires a single argument.
78 Increases the attribute value by the amount of the argument, or by 1 if no
79 argument is given. This method returns the new value.
81 This method accepts a single argument.
87 Decreases the attribute value by the amount of the argument, or by 1 if no
88 argument is given. This method returns the new value.
90 This method accepts a single argument.
94 Resets the value stored in this slot to its default value, and returns the new
101 See L<Moose/BUGS> for details on reporting bugs.
105 Stevan Little E<lt>stevan@iinteractive.comE<gt>
107 =head1 COPYRIGHT AND LICENSE
109 Copyright 2007-2009 by Infinity Interactive, Inc.
111 L<http://www.iinteractive.com>
113 This library is free software; you can redistribute it and/or modify
114 it under the same terms as Perl itself.