2 package Moose::Meta::Attribute::Native::Trait::Counter;
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 use Moose::Meta::Attribute::Native::MethodProvider::Counter;
11 with 'Moose::Meta::Attribute::Native::Trait';
13 has 'method_provider' => (
16 predicate => 'has_method_provider',
17 default => 'Moose::Meta::Attribute::Native::MethodProvider::Counter',
20 sub _default_default { 0 }
21 sub _default_is { 'ro' }
22 sub _helper_type { 'Num' }
34 Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for counters
42 traits => ['Counter'],
49 reset_counter => 'reset',
53 my $page = MyHomePage->new();
54 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
55 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
57 my $count_by_twos = 2;
58 $page->inc_counter($count_by_twos);
62 This module provides a simple counter attribute, which can be
63 incremented and decremented by arbitrary amounts. The default
64 amount of change is one.
66 =head1 PROVIDED METHODS
68 These methods are implemented in
69 L<Moose::Meta::Attribute::Native::MethodProvider::Counter>. It is important to
70 note that all those methods do in place modification of the value stored in
77 Set the counter to the specified value.
81 Increase the attribute value by the amount of the argument.
82 No argument increments the value by 1.
86 Decrease the attribute value by the amount of the argument.
87 No argument decrements the value by 1.
91 Resets the value stored in this slot to it's default value.
101 =item B<method_provider>
103 =item B<has_method_provider>
109 See L<Moose/BUGS> for details on reporting bugs.
113 Stevan Little E<lt>stevan@iinteractive.comE<gt>
115 =head1 COPYRIGHT AND LICENSE
117 Copyright 2007-2009 by Infinity Interactive, Inc.
119 L<http://www.iinteractive.com>
121 This library is free software; you can redistribute it and/or modify
122 it under the same terms as Perl itself.