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