1 package MooseX::AttributeHelpers::Trait::Number;
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
8 with 'MooseX::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])) ) };
64 MooseX::AttributeHelpers::Number
70 use MooseX::AttributeHelpers;
73 metaclass => 'Number',
88 my $real = Real->new();
89 $real->add(5); # same as $real->integer($real->integer + 5);
90 $real->sub(2); # same as $real->integer($real->integer - 2);
94 This provides a simple numeric attribute, which supports most of the
95 basic math operations.
105 =item B<method_constructors>
109 =head1 PROVIDED METHODS
111 It is important to note that all those methods do in place
112 modification of the value stored in the attribute.
116 =item I<set ($value)>
118 Alternate way to set the value.
120 =item I<add ($value)>
122 Adds the current value of the attribute to C<$value>.
124 =item I<sub ($value)>
126 Subtracts the current value of the attribute to C<$value>.
128 =item I<mul ($value)>
130 Multiplies the current value of the attribute to C<$value>.
132 =item I<div ($value)>
134 Divides the current value of the attribute to C<$value>.
136 =item I<mod ($value)>
138 Modulus the current value of the attribute to C<$value>.
142 Sets the current value of the attribute to its absolute value.
148 All complex software has bugs lurking in it, and this module is no
149 exception. If you find a bug please either email me, or add the bug
156 =head1 COPYRIGHT AND LICENSE
158 Copyright 2007-2009 by Infinity Interactive, Inc.
160 L<http://www.iinteractive.com>
162 This library is free software; you can redistribute it and/or modify
163 it under the same terms as Perl itself.