Replace method_provider with a ( future :( ) requires_attr
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / Number.pm
1 package MooseX::AttributeHelpers::Number;
2 use Moose;
3
4 our $VERSION   = '0.02';
5 our $AUTHORITY = 'cpan:STEVAN';
6
7 extends 'Moose::Meta::Attribute';
8 with 'MooseX::AttributeHelpers::Trait::Number';
9
10 no Moose;
11
12 # register the alias ...
13 package # hide me from search.cpan.org
14     Moose::Meta::Attribute::Custom::Number;
15 sub register_implementation { 'MooseX::AttributeHelpers::Number' }
16
17 1;
18
19 =pod
20
21 =head1 NAME
22
23 MooseX::AttributeHelpers::Number
24
25 =head1 SYNOPSIS
26   
27   package Real;
28   use Moose;
29   use MooseX::AttributeHelpers;
30   
31   has 'integer' => (
32       metaclass => 'Number',
33       is        => 'ro',
34       isa       => 'Int',
35       default   => sub { 5 },
36       provides  => {
37           set => 'set',
38           add => 'add',
39           sub => 'sub',
40           mul => 'mul',
41           div => 'div',
42           mod => 'mod',
43           abs => 'abs',
44       }
45   );
46
47   my $real = Real->new();
48   $real->add(5); # same as $real->integer($real->integer + 5);
49   $real->sub(2); # same as $real->integer($real->integer - 2);  
50   
51 =head1 DESCRIPTION
52
53 This provides a simple numeric attribute, which supports most of the
54 basic math operations.
55
56 =head1 METHODS
57
58 =over 4
59
60 =item B<meta>
61
62 =item B<helper_type>
63
64 =item B<method_constructors>
65
66 =back
67
68 =head1 PROVIDED METHODS
69
70 It is important to note that all those methods do in place
71 modification of the value stored in the attribute.
72
73 =over 4
74
75 =item I<set ($value)>
76
77 Alternate way to set the value.
78
79 =item I<add ($value)>
80
81 Adds the current value of the attribute to C<$value>.
82
83 =item I<sub ($value)>
84
85 Subtracts the current value of the attribute to C<$value>.
86
87 =item I<mul ($value)>
88
89 Multiplies the current value of the attribute to C<$value>.
90
91 =item I<div ($value)>
92
93 Divides the current value of the attribute to C<$value>.
94
95 =item I<mod ($value)>
96
97 Modulus the current value of the attribute to C<$value>.
98
99 =item I<abs>
100
101 Sets the current value of the attribute to its absolute value.
102
103 =back
104
105 =head1 BUGS
106
107 All complex software has bugs lurking in it, and this module is no 
108 exception. If you find a bug please either email me, or add the bug
109 to cpan-RT.
110
111 =head1 AUTHOR
112
113 Robert Boone
114
115 =head1 COPYRIGHT AND LICENSE
116
117 Copyright 2007-2008 by Infinity Interactive, Inc.
118
119 L<http://www.iinteractive.com>
120
121 This library is free software; you can redistribute it and/or modify
122 it under the same terms as Perl itself.
123
124 =cut