2 package Moose::Meta::Attribute::Native::Trait::Counter;
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 use Moose::Meta::Method::Accessor::Native::Counter::dec;
10 use Moose::Meta::Method::Accessor::Native::Counter::inc;
11 use Moose::Meta::Method::Accessor::Native::Counter::reset;
12 use Moose::Meta::Method::Accessor::Native::Counter::set;
14 with 'Moose::Meta::Attribute::Native::Trait' =>
15 { -excludes => ['_root_types'] };
17 sub _default_default { 0 }
18 sub _default_is { 'ro' }
19 sub _helper_type { 'Num' }
20 sub _native_type { 'Counter' }
21 sub _root_types { 'Num', 'Int' }
33 Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for counters
41 traits => ['Counter'],
48 reset_counter => 'reset',
52 my $page = MyHomePage->new();
53 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
54 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
56 my $count_by_twos = 2;
57 $page->inc_counter($count_by_twos);
61 This module provides a simple counter attribute, which can be
62 incremented and decremented by arbitrary amounts. The default
63 amount of change is one.
65 =head1 PROVIDED METHODS
67 These methods are implemented in
68 L<Moose::Meta::Attribute::Native::MethodProvider::Counter>. It is important to
69 note that all those methods do in place modification of the value stored in
76 Set the counter to the specified value.
80 Increase the attribute value by the amount of the argument.
81 No argument increments the value by 1.
85 Decrease the attribute value by the amount of the argument.
86 No argument decrements the value by 1.
90 Resets the value stored in this slot to it's default value.
100 =item B<method_provider>
102 =item B<has_method_provider>
108 See L<Moose/BUGS> for details on reporting bugs.
112 Stevan Little E<lt>stevan@iinteractive.comE<gt>
114 =head1 COPYRIGHT AND LICENSE
116 Copyright 2007-2009 by Infinity Interactive, Inc.
118 L<http://www.iinteractive.com>
120 This library is free software; you can redistribute it and/or modify
121 it under the same terms as Perl itself.