Commit | Line | Data |
c466e58f |
1 | package Moose::Meta::Attribute::Native::Trait::Number; |
e3c07b19 |
2 | use Moose::Role; |
3 | |
bb8ef151 |
4 | our $VERSION = '1.9900'; |
e3c07b19 |
5 | $VERSION = eval $VERSION; |
6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | |
c466e58f |
8 | with 'Moose::Meta::Attribute::Native::Trait'; |
e3c07b19 |
9 | |
2e069f5a |
10 | sub _helper_type { 'Num' } |
e3c07b19 |
11 | |
e3c07b19 |
12 | no Moose::Role; |
13 | |
e3c07b19 |
14 | 1; |
15 | |
16 | =pod |
17 | |
18 | =head1 NAME |
19 | |
2420461c |
20 | Moose::Meta::Attribute::Native::Trait::Number - Helper trait for Num attributes |
e3c07b19 |
21 | |
22 | =head1 SYNOPSIS |
23 | |
24 | package Real; |
25 | use Moose; |
e3c07b19 |
26 | |
27 | has 'integer' => ( |
e132fd56 |
28 | traits => ['Number'], |
29 | is => 'ro', |
30 | isa => 'Num', |
31 | default => 5, |
32 | handles => { |
e3c07b19 |
33 | set => 'set', |
34 | add => 'add', |
35 | sub => 'sub', |
36 | mul => 'mul', |
37 | div => 'div', |
38 | mod => 'mod', |
39 | abs => 'abs', |
9610c1d2 |
40 | }, |
e3c07b19 |
41 | ); |
42 | |
43 | my $real = Real->new(); |
e132fd56 |
44 | $real->add(5); # same as $real->integer($real->integer + 5); |
45 | $real->sub(2); # same as $real->integer($real->integer - 2); |
e3c07b19 |
46 | |
47 | =head1 DESCRIPTION |
48 | |
7795e4de |
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>. |
e3c07b19 |
57 | |
e3c07b19 |
58 | =head1 PROVIDED METHODS |
59 | |
7795e4de |
60 | All of these methods modify the attribute's value in place. All methods return |
61 | the new value. |
e3c07b19 |
62 | |
63 | =over 4 |
64 | |
e132fd56 |
65 | =item * B<add($value)> |
e3c07b19 |
66 | |
7795e4de |
67 | Adds the current value of the attribute to C<$value>. |
e3c07b19 |
68 | |
e132fd56 |
69 | =item * B<sub($value)> |
e3c07b19 |
70 | |
7795e4de |
71 | Subtracts C<$value> from the current value of the attribute. |
e3c07b19 |
72 | |
e132fd56 |
73 | =item * B<mul($value)> |
e3c07b19 |
74 | |
7795e4de |
75 | Multiplies the current value of the attribute by C<$value>. |
e3c07b19 |
76 | |
e132fd56 |
77 | =item * B<div($value)> |
e3c07b19 |
78 | |
7795e4de |
79 | Divides the current value of the attribute by C<$value>. |
e3c07b19 |
80 | |
e132fd56 |
81 | =item * B<mod($value)> |
e3c07b19 |
82 | |
7795e4de |
83 | Returns the current value of the attribute modulo C<$value>. |
e3c07b19 |
84 | |
e132fd56 |
85 | =item * B<abs> |
e3c07b19 |
86 | |
7795e4de |
87 | Sets the current value of the attribute to its absolute value. |
ace7cdf9 |
88 | |
89 | =back |
90 | |
e3c07b19 |
91 | =head1 BUGS |
92 | |
d4048ef3 |
93 | See L<Moose/BUGS> for details on reporting bugs. |
e3c07b19 |
94 | |
95 | =head1 AUTHOR |
96 | |
97 | Robert Boone |
98 | |
99 | =head1 COPYRIGHT AND LICENSE |
100 | |
8e5dd3fb |
101 | Copyright 2007-2010 by Infinity Interactive, Inc. |
e3c07b19 |
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 |