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