stop using excludes within moose, since it's no longer necessary
[gitmo/Moose.git] / lib / Moose / Meta / Attribute / Native / Trait / Counter.pm
CommitLineData
e3c07b19 1
c466e58f 2package Moose::Meta::Attribute::Native::Trait::Counter;
e3c07b19 3use Moose::Role;
4
00bbc132 5with 'Moose::Meta::Attribute::Native::Trait';
e3c07b19 6
2edb73d9 7sub _default_default { 0 }
8sub _default_is { 'ro' }
2e069f5a 9sub _helper_type { 'Num' }
04e05413 10sub _root_types { 'Num', 'Int' }
e3c07b19 11
e3c07b19 12no Moose::Role;
13
e3c07b19 141;
15
e818d161 16# ABSTRACT: Helper trait for Int attributes which represent counters
ad46f524 17
e3c07b19 18__END__
19
20=pod
21
e3c07b19 22=head1 SYNOPSIS
23
24 package MyHomePage;
25 use Moose;
e3c07b19 26
27 has 'counter' => (
e132fd56 28 traits => ['Counter'],
29 is => 'ro',
30 isa => 'Num',
31 default => 0,
32 handles => {
5f3663b2 33 inc_counter => 'inc',
34 dec_counter => 'dec',
35 reset_counter => 'reset',
9610c1d2 36 },
e3c07b19 37 );
38
39 my $page = MyHomePage->new();
e132fd56 40 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
41 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
42
aa276b31 43 my $count_by_twos = 2;
44 $page->inc_counter($count_by_twos);
e3c07b19 45
46=head1 DESCRIPTION
47
7795e4de 48This trait provides native delegation methods for counters. A counter can be
49any sort of number (integer or not). The delegation methods allow you to
50increment, decrement, or reset the value.
51
52=head1 DEFAULT TYPE
53
54If you don't provide an C<isa> value for your attribute, it will default to
55C<Num>.
e3c07b19 56
e3c07b19 57=head1 PROVIDED METHODS
58
e3c07b19 59=over 4
60
e132fd56 61=item * B<set($value)>
e3c07b19 62
e132fd56 63Sets the counter to the specified value and returns the new value.
e3c07b19 64
e132fd56 65This method requires a single argument.
e3c07b19 66
e132fd56 67=item * B<inc>
e3c07b19 68
e132fd56 69=item * B<inc($arg)>
e3c07b19 70
e132fd56 71Increases the attribute value by the amount of the argument, or by 1 if no
72argument is given. This method returns the new value.
e3c07b19 73
e132fd56 74This method accepts a single argument.
e3c07b19 75
e132fd56 76=item * B<dec>
e3c07b19 77
e132fd56 78=item * B<dec($arg)>
e3c07b19 79
e132fd56 80Decreases the attribute value by the amount of the argument, or by 1 if no
81argument is given. This method returns the new value.
7250a968 82
e132fd56 83This method accepts a single argument.
84
85=item * B<reset>
7250a968 86
e132fd56 87Resets the value stored in this slot to its default value, and returns the new
88value.
7250a968 89
7250a968 90=back
91
e3c07b19 92=head1 BUGS
93
d4048ef3 94See L<Moose/BUGS> for details on reporting bugs.
e3c07b19 95
e3c07b19 96=cut