Inline all Counter methods
[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 our $VERSION   = '1.14';
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
8
9 use Moose::Meta::Method::Accessor::Native::Counter::dec;
10 use Moose::Meta::Method::Accessor::Native::Counter::inc;
11 use Moose::Meta::Method::Accessor::Native::Counter::reset;
12 use Moose::Meta::Method::Accessor::Native::Counter::set;
13
14 with 'Moose::Meta::Attribute::Native::Trait' =>
15     { -excludes => ['_root_types'] };
16
17 sub _default_default { 0 }
18 sub _default_is { 'ro' }
19 sub _helper_type { 'Num' }
20 sub _native_type { 'Counter' }
21 sub _root_types { 'Num', 'Int' }
22
23 no Moose::Role;
24
25 1;
26
27 __END__
28
29 =pod
30
31 =head1 NAME
32
33 Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for counters
34
35 =head1 SYNOPSIS
36
37   package MyHomePage;
38   use Moose;
39
40   has 'counter' => (
41       traits    => ['Counter'],
42       is        => 'ro',
43       isa       => 'Num',
44       default   => 0,
45       handles   => {
46           inc_counter   => 'inc',
47           dec_counter   => 'dec',
48           reset_counter => 'reset',
49       },
50   );
51
52   my $page = MyHomePage->new();
53   $page->inc_counter; # same as $page->counter( $page->counter + 1 );
54   $page->dec_counter; # same as $page->counter( $page->counter - 1 );
55   
56   my $count_by_twos = 2;
57   $page->inc_counter($count_by_twos);
58
59 =head1 DESCRIPTION
60
61 This module provides a simple counter attribute, which can be
62 incremented and decremented by arbitrary amounts.  The default
63 amount of change is one.
64
65 =head1 PROVIDED METHODS
66
67 These methods are implemented in
68 L<Moose::Meta::Attribute::Native::MethodProvider::Counter>. It is important to
69 note that all those methods do in place modification of the value stored in
70 the attribute.
71
72 =over 4
73
74 =item B<set($value)>
75
76 Set the counter to the specified value.
77
78 =item B<inc($arg)>
79
80 Increase the attribute value by the amount of the argument.  
81 No argument increments the value by 1. 
82
83 =item B<dec($arg)>
84
85 Decrease the attribute value by the amount of the argument.  
86 No argument decrements the value by 1.
87
88 =item B<reset>
89
90 Resets the value stored in this slot to it's default value.
91
92 =back
93
94 =head1 METHODS
95
96 =over 4
97
98 =item B<meta>
99
100 =item B<method_provider>
101
102 =item B<has_method_provider>
103
104 =back
105
106 =head1 BUGS
107
108 See L<Moose/BUGS> for details on reporting bugs.
109
110 =head1 AUTHOR
111
112 Stevan Little E<lt>stevan@iinteractive.comE<gt>
113
114 =head1 COPYRIGHT AND LICENSE
115
116 Copyright 2007-2009 by Infinity Interactive, Inc.
117
118 L<http://www.iinteractive.com>
119
120 This library is free software; you can redistribute it and/or modify
121 it under the same terms as Perl itself.
122
123 =cut