0.02
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / Counter.pm
CommitLineData
22d869ff 1
2package MooseX::AttributeHelpers::Counter;
3use Moose;
22d869ff 4
5our $VERSION = '0.01';
6our $AUTHORITY = 'cpan:STEVAN';
7
8e3fab6d 8use MooseX::AttributeHelpers::MethodProvider::Counter;
d26633fc 9
8e3fab6d 10extends 'MooseX::AttributeHelpers::Base';
8ba40fb0 11
8e3fab6d 12has '+method_provider' => (
13 default => 'MooseX::AttributeHelpers::MethodProvider::Counter'
d26633fc 14);
8e3fab6d 15
16sub helper_type { 'Num' }
22d869ff 17
22d869ff 18no Moose;
22d869ff 19
20# register the alias ...
21package Moose::Meta::Attribute::Custom::Counter;
22sub register_implementation { 'MooseX::AttributeHelpers::Counter' }
23
241;
25
26__END__
27
28=pod
29
30=head1 NAME
31
32MooseX::AttributeHelpers::Counter
33
34=head1 SYNOPSIS
35
36 package MyHomePage;
37 use Moose;
5431dff2 38 use MooseX::AttributeHelpers;
22d869ff 39
40 has 'counter' => (
41 metaclass => 'Counter',
42 is => 'rw',
43 isa => 'Int',
44 default => sub { 0 },
45 provides => {
46 inc => 'inc_counter',
21c7045b 47 dec => 'dec_counter',
22d869ff 48 }
49 );
50
51 my $page = MyHomePage->new();
52 $page->inc_counter; # same as $page->counter($page->counter + 1);
21c7045b 53 $page->dec_counter; # same as $page->counter($page->counter - 1);
22d869ff 54
55=head1 DESCRIPTION
56
5431dff2 57This module provides a simple counter attribute, which can be
58incremented and decremeneted.
59
22d869ff 60=head1 METHODS
61
5431dff2 62=over 4
63
64=item B<method_provider>
65
66=item B<has_method_provider>
67
68=item B<helper_type>
69
70=back
71
c91a1347 72=head1 PROVIDED METHODS
73
74It is important to note that all those methods do in place
75modification of the value stored in the attribute.
76
77=over 4
78
79=item I<inc>
80
81Increments the value stored in this slot by 1.
82
83=item I<dec>
84
85Decrements the value stored in this slot by 1.
86
87=item I<reset>
88
89Resets the value stored in this slot to it's default value.
90
91=back
92
22d869ff 93=head1 BUGS
94
95All complex software has bugs lurking in it, and this module is no
96exception. If you find a bug please either email me, or add the bug
97to cpan-RT.
98
99=head1 AUTHOR
100
101Stevan Little E<lt>stevan@iinteractive.comE<gt>
102
103=head1 COPYRIGHT AND LICENSE
104
105Copyright 2007 by Infinity Interactive, Inc.
106
107L<http://www.iinteractive.com>
108
109This library is free software; you can redistribute it and/or modify
110it under the same terms as Perl itself.
111
112=cut