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