Composite now implemented.
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / Counter.pm
1 package MooseX::AttributeHelpers::Counter;
2 use Moose;
3 use MooseX::AttributeHelpers::MethodProvider::Counter;
4
5 extends 'MooseX::AttributeHelpers::Base';
6
7 our $VERSION   = '0.03';
8 our $AUTHORITY = 'cpan:STEVAN';
9
10 __PACKAGE__->sugar(
11     default_options  => {
12         is      => 'ro', 
13         default => 0,
14     },
15
16     auto_provide     => 1,
17     method_provider  => 'Counter',
18     shortcut         => 'Counter',
19 );
20
21 no Moose;
22
23 1;
24
25 __END__
26
27 =pod
28
29 =head1 NAME
30
31 MooseX::AttributeHelpers::Counter
32
33 =head1 SYNOPSIS
34
35   package MyHomePage;
36   use Moose;
37   use MooseX::AttributeHelpers;
38   
39   has 'counter' => (
40       metaclass => 'Counter',
41       is        => 'ro',
42       isa       => 'Num',
43       default   => sub { 0 },
44       provides  => {
45           inc => 'inc_counter',
46           dec => 'dec_counter',          
47           reset => 'reset_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 incremented and 
58 decremented.  It is important to note that all those methods do in place 
59 modification of the value stored in the attribute.
60
61 If your attribute definition does not include any of I<is>, I<isa>,
62 I<default> or I<provides> but does use the C<Counter> metaclass,
63 then this module applies defaults as in the L</SYNOPSIS>
64 above. This allows for a very basic counter definition:
65
66   has 'foo' => (metaclass => 'Counter');
67   $obj->inc_foo;
68
69 =head1 PROVIDED METHODS
70
71 The methods for this metaclass are provided by
72 L<MooseX::AttributeHelpers::MethodProvider::Counter>.
73
74 =head1 BUGS
75
76 All complex software has bugs lurking in it, and this module is no 
77 exception. If you find a bug please either email me, or add the bug
78 to cpan-RT.
79
80 =head1 AUTHOR
81
82 Stevan Little E<lt>stevan@iinteractive.comE<gt>
83
84 =head1 COPYRIGHT AND LICENSE
85
86 Copyright 2007-2008 by Infinity Interactive, Inc.
87
88 L<http://www.iinteractive.com>
89
90 This library is free software; you can redistribute it and/or modify
91 it under the same terms as Perl itself.
92
93 =cut