190abcb3f50aa476981b8bd6ac6aeb58ad14f8be
[gitmo/Moose.git] / lib / Moose / Meta / Attribute / Native / Trait / Number.pm
1 package Moose::Meta::Attribute::Native::Trait::Number;
2 use Moose::Role;
3
4 with 'Moose::Meta::Attribute::Native::Trait';
5
6 sub _helper_type { 'Num' }
7
8 no Moose::Role;
9
10 1;
11
12 =pod
13
14 =head1 SYNOPSIS
15
16   package Real;
17   use Moose;
18
19   has 'integer' => (
20       traits  => ['Number'],
21       is      => 'ro',
22       isa     => 'Num',
23       default => 5,
24       handles => {
25           set => 'set',
26           add => 'add',
27           sub => 'sub',
28           mul => 'mul',
29           div => 'div',
30           mod => 'mod',
31           abs => 'abs',
32       },
33   );
34
35   my $real = Real->new();
36   $real->add(5);    # same as $real->integer($real->integer + 5);
37   $real->sub(2);    # same as $real->integer($real->integer - 2);
38
39 =head1 DESCRIPTION
40
41 This trait provides native delegation methods for numbers. All of the
42 operations correspond to arithmetic operations like addition or
43 multiplication.
44
45 =head1 DEFAULT TYPE
46
47 If you don't provide an C<isa> value for your attribute, it will default to
48 C<Num>.
49
50 =head1 PROVIDED METHODS
51
52 All of these methods modify the attribute's value in place. All methods return
53 the new value.
54
55 =over 4
56
57 =item * B<add($value)>
58
59 Adds the current value of the attribute to C<$value>.
60
61 =item * B<sub($value)>
62
63 Subtracts C<$value> from the current value of the attribute.
64
65 =item * B<mul($value)>
66
67 Multiplies the current value of the attribute by C<$value>.
68
69 =item * B<div($value)>
70
71 Divides the current value of the attribute by C<$value>.
72
73 =item * B<mod($value)>
74
75 Returns the current value of the attribute modulo C<$value>.
76
77 =item * B<abs>
78
79 Sets the current value of the attribute to its absolute value.
80
81 =back
82
83 =head1 BUGS
84
85 See L<Moose/BUGS> for details on reporting bugs.
86
87 =cut