stop using excludes within moose, since it's no longer necessary
[gitmo/Moose.git] / lib / Moose / Meta / Attribute / Native / Trait / Counter.pm
1
2 package Moose::Meta::Attribute::Native::Trait::Counter;
3 use Moose::Role;
4
5 with 'Moose::Meta::Attribute::Native::Trait';
6
7 sub _default_default { 0 }
8 sub _default_is { 'ro' }
9 sub _helper_type { 'Num' }
10 sub _root_types { 'Num', 'Int' }
11
12 no Moose::Role;
13
14 1;
15
16 # ABSTRACT: Helper trait for Int attributes which represent counters
17
18 __END__
19
20 =pod
21
22 =head1 SYNOPSIS
23
24   package MyHomePage;
25   use Moose;
26
27   has 'counter' => (
28       traits  => ['Counter'],
29       is      => 'ro',
30       isa     => 'Num',
31       default => 0,
32       handles => {
33           inc_counter   => 'inc',
34           dec_counter   => 'dec',
35           reset_counter => 'reset',
36       },
37   );
38
39   my $page = MyHomePage->new();
40   $page->inc_counter;    # same as $page->counter( $page->counter + 1 );
41   $page->dec_counter;    # same as $page->counter( $page->counter - 1 );
42
43   my $count_by_twos = 2;
44   $page->inc_counter($count_by_twos);
45
46 =head1 DESCRIPTION
47
48 This trait provides native delegation methods for counters. A counter can be
49 any sort of number (integer or not). The delegation methods allow you to
50 increment, decrement, or reset the value.
51
52 =head1 DEFAULT TYPE
53
54 If you don't provide an C<isa> value for your attribute, it will default to
55 C<Num>.
56
57 =head1 PROVIDED METHODS
58
59 =over 4
60
61 =item * B<set($value)>
62
63 Sets the counter to the specified value and returns the new value.
64
65 This method requires a single argument.
66
67 =item * B<inc>
68
69 =item * B<inc($arg)>
70
71 Increases the attribute value by the amount of the argument, or by 1 if no
72 argument is given. This method returns the new value.
73
74 This method accepts a single argument.
75
76 =item * B<dec>
77
78 =item * B<dec($arg)>
79
80 Decreases the attribute value by the amount of the argument, or by 1 if no
81 argument is given. This method returns the new value.
82
83 This method accepts a single argument.
84
85 =item * B<reset>
86
87 Resets the value stored in this slot to its default value, and returns the new
88 value.
89
90 =back
91
92 =head1 BUGS
93
94 See L<Moose/BUGS> for details on reporting bugs.
95
96 =cut