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