Merge branch 'master' into traits
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / Counter.pm
CommitLineData
22d869ff 1
2package MooseX::AttributeHelpers::Counter;
3use Moose;
22d869ff 4
9e2db1c2 5our $VERSION = '0.17';
38430345 6$VERSION = eval $VERSION;
22d869ff 7our $AUTHORITY = 'cpan:STEVAN';
8
0224b8d2 9extends 'Moose::Meta::Attribute';
10with 'MooseX::AttributeHelpers::Trait::Counter';
38abf787 11
22d869ff 12no Moose;
22d869ff 13
14# register the alias ...
0f31cc28 15package # hide me from search.cpan.org
16 Moose::Meta::Attribute::Custom::Counter;
22d869ff 17sub register_implementation { 'MooseX::AttributeHelpers::Counter' }
18
191;
20
21__END__
22
23=pod
24
25=head1 NAME
26
27MooseX::AttributeHelpers::Counter
28
29=head1 SYNOPSIS
30
31 package MyHomePage;
32 use Moose;
5431dff2 33 use MooseX::AttributeHelpers;
22d869ff 34
35 has 'counter' => (
36 metaclass => 'Counter',
38abf787 37 is => 'ro',
38 isa => 'Num',
22d869ff 39 default => sub { 0 },
40 provides => {
41 inc => 'inc_counter',
21c7045b 42 dec => 'dec_counter',
38abf787 43 reset => 'reset_counter',
22d869ff 44 }
45 );
46
47 my $page = MyHomePage->new();
48 $page->inc_counter; # same as $page->counter($page->counter + 1);
21c7045b 49 $page->dec_counter; # same as $page->counter($page->counter - 1);
22d869ff 50
51=head1 DESCRIPTION
52
5431dff2 53This module provides a simple counter attribute, which can be
54incremented and decremeneted.
55
38abf787 56If your attribute definition does not include any of I<is>, I<isa>,
57I<default> or I<provides> but does use the C<Counter> metaclass,
58then this module applies defaults as in the L</SYNOPSIS>
59above. This allows for a very basic counter definition:
60
61 has 'foo' => (metaclass => 'Counter');
62 $obj->inc_foo;
63
22d869ff 64=head1 METHODS
65
5431dff2 66=over 4
67
b91f57af 68=item B<meta>
69
5431dff2 70=item B<method_provider>
71
72=item B<has_method_provider>
73
74=item B<helper_type>
75
38abf787 76=item B<process_options_for_provides>
77
78Run before its superclass method.
79
829736f9 80=item B<check_provides_values>
81
82Run after its superclass method.
83
5431dff2 84=back
85
c91a1347 86=head1 PROVIDED METHODS
87
88It is important to note that all those methods do in place
89modification of the value stored in the attribute.
90
91=over 4
92
eef0ea50 93=item I<set>
94
95Set the counter to the specified value.
96
c91a1347 97=item I<inc>
98
1aa9e3c9 99Increments the value stored in this slot by 1. Providing an argument will
eef0ea50 100cause the counter to be increased by specified amount.
c91a1347 101
102=item I<dec>
103
eef0ea50 104Decrements the value stored in this slot by 1. Providing an argument will
105cause the counter to be increased by specified amount.
c91a1347 106
107=item I<reset>
108
eef0ea50 109Resets the value stored in this slot to it's default value.
c91a1347 110
111=back
112
22d869ff 113=head1 BUGS
114
115All complex software has bugs lurking in it, and this module is no
116exception. If you find a bug please either email me, or add the bug
117to cpan-RT.
118
119=head1 AUTHOR
120
121Stevan Little E<lt>stevan@iinteractive.comE<gt>
122
123=head1 COPYRIGHT AND LICENSE
124
99c62fb8 125Copyright 2007-2008 by Infinity Interactive, Inc.
22d869ff 126
127L<http://www.iinteractive.com>
128
129This library is free software; you can redistribute it and/or modify
130it under the same terms as Perl itself.
131
38abf787 132=cut