20e9359c5afac578c6b5086829651b777a37a496
[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.14';
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
7
8 use Moose::Meta::Method::Accessor::Native::Number::abs;
9 use Moose::Meta::Method::Accessor::Native::Number::add;
10 use Moose::Meta::Method::Accessor::Native::Number::div;
11 use Moose::Meta::Method::Accessor::Native::Number::mod;
12 use Moose::Meta::Method::Accessor::Native::Number::mul;
13 use Moose::Meta::Method::Accessor::Native::Number::set;
14 use Moose::Meta::Method::Accessor::Native::Number::sub;
15
16 with 'Moose::Meta::Attribute::Native::Trait';
17
18 sub _helper_type { 'Num' }
19
20 no Moose::Role;
21
22 1;
23
24 =pod
25
26 =head1 NAME
27
28 Moose::Meta::Attribute::Native::Trait::Number - Helper trait for Num attributes
29
30 =head1 SYNOPSIS
31
32   package Real;
33   use Moose;
34
35   has 'integer' => (
36       traits    => ['Number'],
37       is        => 'ro',
38       isa       => 'Num',
39       default   => 5,
40       handles   => {
41           set => 'set',
42           add => 'add',
43           sub => 'sub',
44           mul => 'mul',
45           div => 'div',
46           mod => 'mod',
47           abs => 'abs',
48       },
49   );
50
51   my $real = Real->new();
52   $real->add(5); # same as $real->integer($real->integer + 5);
53   $real->sub(2); # same as $real->integer($real->integer - 2);
54
55 =head1 DESCRIPTION
56
57 This provides a simple numeric attribute, which supports most of the
58 basic math operations.
59
60 =head1 PROVIDED METHODS
61
62 It is important to note that all those methods do in place modification of the
63 value stored in the attribute. These methods are implemented within this
64 package.
65
66 =over 4
67
68 =item B<set($value)>
69
70 Alternate way to set the value.
71
72 =item B<add($value)>
73
74 Adds the current value of the attribute to C<$value>.
75
76 =item B<sub($value)>
77
78 Subtracts C<$value> from the current value of the attribute.
79
80 =item B<mul($value)>
81
82 Multiplies the current value of the attribute by C<$value>.
83
84 =item B<div($value)>
85
86 Divides the current value of the attribute by C<$value>.
87
88 =item B<mod($value)>
89
90 Returns the current value of the attribute modulo C<$value>.
91
92 =item B<abs>
93
94 Sets the current value of the attribute to its absolute value.
95
96 =back
97
98 =head1 METHODS
99
100 =over 4
101
102 =item B<meta>
103
104 =item B<method_constructors>
105
106 =back
107
108 =head1 BUGS
109
110 See L<Moose/BUGS> for details on reporting bugs.
111
112 =head1 AUTHOR
113
114 Robert Boone
115
116 =head1 COPYRIGHT AND LICENSE
117
118 Copyright 2007-2009 by Infinity Interactive, Inc.
119
120 L<http://www.iinteractive.com>
121
122 This library is free software; you can redistribute it and/or modify
123 it under the same terms as Perl itself.
124
125 =cut