Commit | Line | Data |
e3c07b19 |
1 | |
2 | package Moose::AttributeHelpers::MethodProvider::Counter; |
3 | use Moose::Role; |
4 | |
115601b6 |
5 | our $VERSION = '0.85'; |
e3c07b19 |
6 | $VERSION = eval $VERSION; |
7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | |
9 | sub reset : method { |
046c8b5e |
10 | my ( $attr, $reader, $writer ) = @_; |
11 | return sub { $writer->( $_[0], $attr->default( $_[0] ) ) }; |
e3c07b19 |
12 | } |
13 | |
14 | sub set : method { |
046c8b5e |
15 | my ( $attr, $reader, $writer, $value ) = @_; |
16 | return sub { $writer->( $_[0], $_[1] ) }; |
e3c07b19 |
17 | } |
18 | |
19 | sub inc { |
046c8b5e |
20 | my ( $attr, $reader, $writer ) = @_; |
21 | return sub { |
22 | $writer->( $_[0], |
23 | $reader->( $_[0] ) + ( defined( $_[1] ) ? $_[1] : 1 ) ); |
24 | }; |
e3c07b19 |
25 | } |
26 | |
27 | sub dec { |
046c8b5e |
28 | my ( $attr, $reader, $writer ) = @_; |
29 | return sub { |
30 | $writer->( $_[0], |
31 | $reader->( $_[0] ) - ( defined( $_[1] ) ? $_[1] : 1 ) ); |
32 | }; |
e3c07b19 |
33 | } |
34 | |
35 | 1; |
36 | |
37 | __END__ |
38 | |
39 | =pod |
40 | |
41 | =head1 NAME |
42 | |
43 | Moose::AttributeHelpers::MethodProvider::Counter |
44 | |
45 | =head1 DESCRIPTION |
46 | |
47 | This is a role which provides the method generators for |
48 | L<Moose::AttributeHelpers::Counter>. |
49 | |
50 | =head1 METHODS |
51 | |
52 | =over 4 |
53 | |
54 | =item B<meta> |
55 | |
56 | =back |
57 | |
58 | =head1 PROVIDED METHODS |
59 | |
60 | =over 4 |
61 | |
62 | =item B<set> |
63 | |
64 | =item B<inc> |
65 | |
66 | =item B<dec> |
67 | |
68 | =item B<reset> |
69 | |
70 | =back |
71 | |
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-2009 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 |