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 trait provides native delegation methods for counters. A counter can be
61 any sort of number (integer or not). The delegation methods allow you to
62 increment, decrement, or reset the value.
66 If you don't provide an C<isa> value for your attribute, it will default to
69 =head1 PROVIDED METHODS
73 =item * B<set($value)>
75 Sets the counter to the specified value and returns the new value.
77 This method requires a single argument.
83 Increases the attribute value by the amount of the argument, or by 1 if no
84 argument is given. This method returns the new value.
86 This method accepts a single argument.
92 Decreases the attribute value by the amount of the argument, or by 1 if no
93 argument is given. This method returns the new value.
95 This method accepts a single argument.
99 Resets the value stored in this slot to its default value, and returns the new
106 See L<Moose/BUGS> for details on reporting bugs.
110 Stevan Little E<lt>stevan@iinteractive.comE<gt>
112 =head1 COPYRIGHT AND LICENSE
114 Copyright 2007-2009 by Infinity Interactive, Inc.
116 L<http://www.iinteractive.com>
118 This library is free software; you can redistribute it and/or modify
119 it under the same terms as Perl itself.