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