2 package Moose::Meta::Attribute::Native::Trait::Counter;
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 use Moose::Meta::Attribute::Native::MethodProvider::Counter;
11 with 'Moose::Meta::Attribute::Native::Trait';
13 has 'method_provider' => (
16 predicate => 'has_method_provider',
17 default => 'Moose::Meta::Attribute::Native::MethodProvider::Counter',
20 sub _default_default { 0 }
21 sub _default_is { 'ro' }
22 sub _helper_type { 'Num' }
24 after '_check_handles_values' => sub {
26 my $handles = $self->handles;
28 unless ( scalar keys %$handles ) {
29 my $method_constructors = $self->method_constructors;
30 my $attr_name = $self->name;
32 foreach my $method ( keys %$method_constructors ) {
33 $handles->{ $method . '_' . $attr_name } = $method;
36 $self->_set_handles($handles);
50 Moose::Meta::Attribute::Native::Trait::Counter
56 use Moose::AttributeHelpers;
59 traits => ['Counter'],
66 reset_counter => 'reset',
70 my $page = MyHomePage->new();
71 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
72 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
76 This module provides a simple counter attribute, which can be
77 incremented and decremented.
79 If your attribute definition does not include any of I<is>, I<isa>,
80 I<default> or I<handles> but does use the C<Counter> trait,
81 then this module applies defaults as in the L</SYNOPSIS>
82 above. This allows for a very basic counter definition:
84 has 'foo' => (traits => ['Counter']);
87 =head1 PROVIDED METHODS
89 These methods are implemented in
90 L<Moose::Meta::Attribute::Native::MethodProvider::Counter>. It is important to
91 note that all those methods do in place modification of the value stored in
98 Set the counter to the specified value.
102 Increments the value stored in this slot by 1. Providing an argument will
103 cause the counter to be increased by specified amount.
107 Decrements the value stored in this slot by 1. Providing an argument will
108 cause the counter to be increased by specified amount.
112 Resets the value stored in this slot to it's default value.
122 =item B<method_provider>
124 =item B<has_method_provider>
130 All complex software has bugs lurking in it, and this module is no
131 exception. If you find a bug please either email me, or add the bug
136 Stevan Little E<lt>stevan@iinteractive.comE<gt>
138 =head1 COPYRIGHT AND LICENSE
140 Copyright 2007-2009 by Infinity Interactive, Inc.
142 L<http://www.iinteractive.com>
144 This library is free software; you can redistribute it and/or modify
145 it under the same terms as Perl itself.