Commit | Line | Data |
22d869ff |
1 | package MooseX::AttributeHelpers::Counter; |
2 | use Moose; |
786dbc3d |
3 | use MooseX::AttributeHelpers::MethodProvider::Counter; |
8683383a |
4 | |
5 | extends 'MooseX::AttributeHelpers::Base'; |
22d869ff |
6 | |
9a976497 |
7 | our $VERSION = '0.03'; |
22d869ff |
8 | our $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 |
21 | no Moose; |
22d869ff |
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; |
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 |
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. |
5431dff2 |
60 | |
38abf787 |
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 | |
c91a1347 |
69 | =head1 PROVIDED METHODS |
70 | |
720fa35b |
71 | The methods for this metaclass are provided by |
72 | L<MooseX::AttributeHelpers::MethodProvider::Counter>. |
c91a1347 |
73 | |
22d869ff |
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 | |
99c62fb8 |
86 | Copyright 2007-2008 by Infinity Interactive, Inc. |
22d869ff |
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 | |
38abf787 |
93 | =cut |