bump version to 1.19
[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
245478d5 4our $VERSION = '1.19';
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' => (
e132fd56 36 traits => ['Number'],
37 is => 'ro',
38 isa => 'Num',
39 default => 5,
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();
e132fd56 52 $real->add(5); # same as $real->integer($real->integer + 5);
53 $real->sub(2); # same as $real->integer($real->integer - 2);
e3c07b19 54
55=head1 DESCRIPTION
56
7795e4de 57This trait provides native delegation methods for numbers. All of the
58operations correspond to arithmetic operations like addition or
59multiplication.
60
61=head1 DEFAULT TYPE
62
63If you don't provide an C<isa> value for your attribute, it will default to
64C<Num>.
e3c07b19 65
e3c07b19 66=head1 PROVIDED METHODS
67
7795e4de 68All of these methods modify the attribute's value in place. All methods return
69the new value.
e3c07b19 70
71=over 4
72
e132fd56 73=item * B<add($value)>
e3c07b19 74
7795e4de 75Adds the current value of the attribute to C<$value>.
e3c07b19 76
e132fd56 77=item * B<sub($value)>
e3c07b19 78
7795e4de 79Subtracts C<$value> from the current value of the attribute.
e3c07b19 80
e132fd56 81=item * B<mul($value)>
e3c07b19 82
7795e4de 83Multiplies the current value of the attribute by C<$value>.
e3c07b19 84
e132fd56 85=item * B<div($value)>
e3c07b19 86
7795e4de 87Divides the current value of the attribute by C<$value>.
e3c07b19 88
e132fd56 89=item * B<mod($value)>
e3c07b19 90
7795e4de 91Returns the current value of the attribute modulo C<$value>.
e3c07b19 92
e132fd56 93=item * B<abs>
e3c07b19 94
7795e4de 95Sets the current value of the attribute to its absolute value.
ace7cdf9 96
97=back
98
e3c07b19 99=head1 BUGS
100
d4048ef3 101See L<Moose/BUGS> for details on reporting bugs.
e3c07b19 102
103=head1 AUTHOR
104
105Robert Boone
106
107=head1 COPYRIGHT AND LICENSE
108
109Copyright 2007-2009 by Infinity Interactive, Inc.
110
111L<http://www.iinteractive.com>
112
113This library is free software; you can redistribute it and/or modify
114it under the same terms as Perl itself.
115
116=cut