bump copyright year to 2010
[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
bb8ef151 5our $VERSION = '1.9900';
e3c07b19 6$VERSION = eval $VERSION;
7our $AUTHORITY = 'cpan:STEVAN';
8
04e05413 9with 'Moose::Meta::Attribute::Native::Trait' =>
10 { -excludes => ['_root_types'] };
e3c07b19 11
2edb73d9 12sub _default_default { 0 }
13sub _default_is { 'ro' }
2e069f5a 14sub _helper_type { 'Num' }
04e05413 15sub _root_types { 'Num', 'Int' }
e3c07b19 16
e3c07b19 17no Moose::Role;
18
e3c07b19 191;
20
21__END__
22
23=pod
24
25=head1 NAME
26
2420461c 27Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for counters
e3c07b19 28
29=head1 SYNOPSIS
30
31 package MyHomePage;
32 use Moose;
e3c07b19 33
34 has 'counter' => (
e132fd56 35 traits => ['Counter'],
36 is => 'ro',
37 isa => 'Num',
38 default => 0,
39 handles => {
5f3663b2 40 inc_counter => 'inc',
41 dec_counter => 'dec',
42 reset_counter => 'reset',
9610c1d2 43 },
e3c07b19 44 );
45
46 my $page = MyHomePage->new();
e132fd56 47 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
48 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
49
aa276b31 50 my $count_by_twos = 2;
51 $page->inc_counter($count_by_twos);
e3c07b19 52
53=head1 DESCRIPTION
54
7795e4de 55This trait provides native delegation methods for counters. A counter can be
56any sort of number (integer or not). The delegation methods allow you to
57increment, decrement, or reset the value.
58
59=head1 DEFAULT TYPE
60
61If you don't provide an C<isa> value for your attribute, it will default to
62C<Num>.
e3c07b19 63
e3c07b19 64=head1 PROVIDED METHODS
65
e3c07b19 66=over 4
67
e132fd56 68=item * B<set($value)>
e3c07b19 69
e132fd56 70Sets the counter to the specified value and returns the new value.
e3c07b19 71
e132fd56 72This method requires a single argument.
e3c07b19 73
e132fd56 74=item * B<inc>
e3c07b19 75
e132fd56 76=item * B<inc($arg)>
e3c07b19 77
e132fd56 78Increases the attribute value by the amount of the argument, or by 1 if no
79argument is given. This method returns the new value.
e3c07b19 80
e132fd56 81This method accepts a single argument.
e3c07b19 82
e132fd56 83=item * B<dec>
e3c07b19 84
e132fd56 85=item * B<dec($arg)>
e3c07b19 86
e132fd56 87Decreases the attribute value by the amount of the argument, or by 1 if no
88argument is given. This method returns the new value.
7250a968 89
e132fd56 90This method accepts a single argument.
91
92=item * B<reset>
7250a968 93
e132fd56 94Resets the value stored in this slot to its default value, and returns the new
95value.
7250a968 96
7250a968 97=back
98
e3c07b19 99=head1 BUGS
100
d4048ef3 101See L<Moose/BUGS> for details on reporting bugs.
e3c07b19 102
103=head1 AUTHOR
104
105Stevan Little E<lt>stevan@iinteractive.comE<gt>
106
107=head1 COPYRIGHT AND LICENSE
108
8e5dd3fb 109Copyright 2007-2010 by Infinity Interactive, Inc.
e3c07b19 110
111L<http://www.iinteractive.com>
112
113This library is free software; you can redistribute it and/or modify
114it under the same terms as Perl itself.
115
116=cut