Commit | Line | Data |
22d869ff |
1 | |
2 | package MooseX::AttributeHelpers::Counter; |
3 | use Moose; |
22d869ff |
4 | |
5 | our $VERSION = '0.01'; |
6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | |
8e3fab6d |
8 | use MooseX::AttributeHelpers::MethodProvider::Counter; |
d26633fc |
9 | |
8e3fab6d |
10 | extends 'MooseX::AttributeHelpers::Base'; |
8ba40fb0 |
11 | |
8e3fab6d |
12 | has '+method_provider' => ( |
13 | default => 'MooseX::AttributeHelpers::MethodProvider::Counter' |
d26633fc |
14 | ); |
8e3fab6d |
15 | |
16 | sub helper_type { 'Num' } |
22d869ff |
17 | |
22d869ff |
18 | no Moose; |
22d869ff |
19 | |
20 | # register the alias ... |
21 | package Moose::Meta::Attribute::Custom::Counter; |
22 | sub register_implementation { 'MooseX::AttributeHelpers::Counter' } |
23 | |
24 | 1; |
25 | |
26 | __END__ |
27 | |
28 | =pod |
29 | |
30 | =head1 NAME |
31 | |
32 | MooseX::AttributeHelpers::Counter |
33 | |
34 | =head1 SYNOPSIS |
35 | |
36 | package MyHomePage; |
37 | use Moose; |
5431dff2 |
38 | use MooseX::AttributeHelpers; |
22d869ff |
39 | |
40 | has 'counter' => ( |
41 | metaclass => 'Counter', |
42 | is => 'rw', |
43 | isa => 'Int', |
44 | default => sub { 0 }, |
45 | provides => { |
46 | inc => 'inc_counter', |
21c7045b |
47 | dec => 'dec_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 | |
5431dff2 |
57 | This module provides a simple counter attribute, which can be |
58 | incremented and decremeneted. |
59 | |
22d869ff |
60 | =head1 METHODS |
61 | |
5431dff2 |
62 | =over 4 |
63 | |
64 | =item B<method_provider> |
65 | |
66 | =item B<has_method_provider> |
67 | |
68 | =item B<helper_type> |
69 | |
70 | =back |
71 | |
22d869ff |
72 | =head1 BUGS |
73 | |
74 | All complex software has bugs lurking in it, and this module is no |
75 | exception. If you find a bug please either email me, or add the bug |
76 | to cpan-RT. |
77 | |
78 | =head1 AUTHOR |
79 | |
80 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
81 | |
82 | =head1 COPYRIGHT AND LICENSE |
83 | |
84 | Copyright 2007 by Infinity Interactive, Inc. |
85 | |
86 | L<http://www.iinteractive.com> |
87 | |
88 | This library is free software; you can redistribute it and/or modify |
89 | it under the same terms as Perl itself. |
90 | |
91 | =cut |