Inline all Counter methods
[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
b6cca0d5 5our $VERSION = '1.14';
e3c07b19 6$VERSION = eval $VERSION;
7our $AUTHORITY = 'cpan:STEVAN';
8
04e05413 9use Moose::Meta::Method::Accessor::Native::Counter::dec;
10use Moose::Meta::Method::Accessor::Native::Counter::inc;
11use Moose::Meta::Method::Accessor::Native::Counter::reset;
12use Moose::Meta::Method::Accessor::Native::Counter::set;
e3c07b19 13
04e05413 14with 'Moose::Meta::Attribute::Native::Trait' =>
15 { -excludes => ['_root_types'] };
e3c07b19 16
2edb73d9 17sub _default_default { 0 }
18sub _default_is { 'ro' }
2e069f5a 19sub _helper_type { 'Num' }
04e05413 20sub _native_type { 'Counter' }
21sub _root_types { 'Num', 'Int' }
e3c07b19 22
e3c07b19 23no Moose::Role;
24
e3c07b19 251;
26
27__END__
28
29=pod
30
31=head1 NAME
32
2420461c 33Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for counters
e3c07b19 34
35=head1 SYNOPSIS
36
37 package MyHomePage;
38 use Moose;
e3c07b19 39
40 has 'counter' => (
9610c1d2 41 traits => ['Counter'],
e3c07b19 42 is => 'ro',
43 isa => 'Num',
2edb73d9 44 default => 0,
5f3663b2 45 handles => {
46 inc_counter => 'inc',
47 dec_counter => 'dec',
48 reset_counter => 'reset',
9610c1d2 49 },
e3c07b19 50 );
51
52 my $page = MyHomePage->new();
2edb73d9 53 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
54 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
aa276b31 55
56 my $count_by_twos = 2;
57 $page->inc_counter($count_by_twos);
e3c07b19 58
59=head1 DESCRIPTION
60
61This module provides a simple counter attribute, which can be
aa276b31 62incremented and decremented by arbitrary amounts. The default
63amount of change is one.
e3c07b19 64
e3c07b19 65=head1 PROVIDED METHODS
66
7250a968 67These methods are implemented in
68L<Moose::Meta::Attribute::Native::MethodProvider::Counter>. It is important to
69note that all those methods do in place modification of the value stored in
70the attribute.
e3c07b19 71
72=over 4
73
eb465b32 74=item B<set($value)>
e3c07b19 75
76Set the counter to the specified value.
77
aa276b31 78=item B<inc($arg)>
e3c07b19 79
aa276b31 80Increase the attribute value by the amount of the argument.
81No argument increments the value by 1.
e3c07b19 82
aa276b31 83=item B<dec($arg)>
e3c07b19 84
aa276b31 85Decrease the attribute value by the amount of the argument.
86No argument decrements the value by 1.
e3c07b19 87
eb465b32 88=item B<reset>
e3c07b19 89
90Resets the value stored in this slot to it's default value.
91
92=back
93
7250a968 94=head1 METHODS
95
96=over 4
97
98=item B<meta>
99
100=item B<method_provider>
101
102=item B<has_method_provider>
103
104=back
105
e3c07b19 106=head1 BUGS
107
d4048ef3 108See L<Moose/BUGS> for details on reporting bugs.
e3c07b19 109
110=head1 AUTHOR
111
112Stevan Little E<lt>stevan@iinteractive.comE<gt>
113
114=head1 COPYRIGHT AND LICENSE
115
116Copyright 2007-2009 by Infinity Interactive, Inc.
117
118L<http://www.iinteractive.com>
119
120This library is free software; you can redistribute it and/or modify
121it under the same terms as Perl itself.
122
123=cut