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