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