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