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 );
59 This module provides a simple counter attribute, which can be
60 incremented and decremented.
62 If your attribute definition does not include any of I<is>, I<isa>,
63 I<default> or I<handles> but does use the C<Counter> trait,
64 then this module applies defaults as in the L</SYNOPSIS>
65 above. This allows for a very basic counter definition:
67 has 'foo' => (traits => ['Counter']);
70 =head1 PROVIDED METHODS
72 These methods are implemented in
73 L<Moose::Meta::Attribute::Native::MethodProvider::Counter>. It is important to
74 note that all those methods do in place modification of the value stored in
81 Set the counter to the specified value.
85 Increments the value stored in this slot by 1. Providing an argument will
86 cause the counter to be increased by specified amount.
90 Decrements the value stored in this slot by 1. Providing an argument will
91 cause the counter to be increased by specified amount.
95 Resets the value stored in this slot to it's default value.
105 =item B<method_provider>
107 =item B<has_method_provider>
113 All complex software has bugs lurking in it, and this module is no
114 exception. If you find a bug please either email me, or add the bug
119 Stevan Little E<lt>stevan@iinteractive.comE<gt>
121 =head1 COPYRIGHT AND LICENSE
123 Copyright 2007-2009 by Infinity Interactive, Inc.
125 L<http://www.iinteractive.com>
127 This library is free software; you can redistribute it and/or modify
128 it under the same terms as Perl itself.