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