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