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