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