1 package Moose::AttributeHelpers::Trait::Number;
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
8 with 'Moose::AttributeHelpers::Trait::Base';
10 sub helper_type { 'Num' }
13 # we don't use the method provider for this
14 # module since many of the names of the provied
15 # methods would conflict with keywords
18 has 'method_constructors' => (
25 my ($attr, $reader, $writer) = @_;
26 return sub { $writer->($_[0], $_[1]) };
29 my ($attr, $reader, $writer) = @_;
30 return sub { $writer->($_[0], $reader->($_[0]) + $_[1]) };
33 my ($attr, $reader, $writer) = @_;
34 return sub { $writer->($_[0], $reader->($_[0]) - $_[1]) };
37 my ($attr, $reader, $writer) = @_;
38 return sub { $writer->($_[0], $reader->($_[0]) * $_[1]) };
41 my ($attr, $reader, $writer) = @_;
42 return sub { $writer->($_[0], $reader->($_[0]) / $_[1]) };
45 my ($attr, $reader, $writer) = @_;
46 return sub { $writer->($_[0], $reader->($_[0]) % $_[1]) };
49 my ($attr, $reader, $writer) = @_;
50 return sub { $writer->($_[0], abs($reader->($_[0])) ) };
58 # register the alias ...
59 package # hide me from search.cpan.org
60 Moose::Meta::Attribute::Custom::Trait::Number;
61 sub register_implementation { 'Moose::AttributeHelpers::Trait::Number' }
69 Moose::AttributeHelpers::Number
75 use Moose::AttributeHelpers;
78 metaclass => 'Number',
93 my $real = Real->new();
94 $real->add(5); # same as $real->integer($real->integer + 5);
95 $real->sub(2); # same as $real->integer($real->integer - 2);
99 This provides a simple numeric attribute, which supports most of the
100 basic math operations.
110 =item B<method_constructors>
114 =head1 PROVIDED METHODS
116 It is important to note that all those methods do in place
117 modification of the value stored in the attribute.
121 =item I<set ($value)>
123 Alternate way to set the value.
125 =item I<add ($value)>
127 Adds the current value of the attribute to C<$value>.
129 =item I<sub ($value)>
131 Subtracts the current value of the attribute to C<$value>.
133 =item I<mul ($value)>
135 Multiplies the current value of the attribute to C<$value>.
137 =item I<div ($value)>
139 Divides the current value of the attribute to C<$value>.
141 =item I<mod ($value)>
143 Modulus the current value of the attribute to C<$value>.
147 Sets the current value of the attribute to its absolute value.
153 All complex software has bugs lurking in it, and this module is no
154 exception. If you find a bug please either email me, or add the bug
161 =head1 COPYRIGHT AND LICENSE
163 Copyright 2007-2009 by Infinity Interactive, Inc.
165 L<http://www.iinteractive.com>
167 This library is free software; you can redistribute it and/or modify
168 it under the same terms as Perl itself.