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 _root_types { 'Num', 'Int' }
32 Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for counters
40 traits => ['Counter'],
47 reset_counter => 'reset',
51 my $page = MyHomePage->new();
52 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
53 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
55 my $count_by_twos = 2;
56 $page->inc_counter($count_by_twos);
60 This module provides a simple counter attribute, which can be
61 incremented and decremented by arbitrary amounts. The default
62 amount of change is one.
64 =head1 PROVIDED METHODS
66 These methods are implemented in
67 L<Moose::Meta::Attribute::Native::MethodProvider::Counter>. It is important to
68 note that all those methods do in place modification of the value stored in
75 Set the counter to the specified value.
79 Increase the attribute value by the amount of the argument.
80 No argument increments the value by 1.
84 Decrease the attribute value by the amount of the argument.
85 No argument decrements the value by 1.
89 Resets the value stored in this slot to it's default value.
99 =item B<method_provider>
101 =item B<has_method_provider>
107 See L<Moose/BUGS> for details on reporting bugs.
111 Stevan Little E<lt>stevan@iinteractive.comE<gt>
113 =head1 COPYRIGHT AND LICENSE
115 Copyright 2007-2009 by Infinity Interactive, Inc.
117 L<http://www.iinteractive.com>
119 This library is free software; you can redistribute it and/or modify
120 it under the same terms as Perl itself.