1 package MooseX::AttributeHelpers::Number;
5 our $AUTHORITY = 'cpan:STEVAN';
7 extends 'MooseX::AttributeHelpers::Base';
9 sub helper_type { 'Num' }
12 # we don't use the method provider for this
13 # module since many of the names of the provied
14 # methods would conflict with keywords
17 has '+method_constructors' => (
21 my ($attr, $reader, $writer) = @_;
22 return sub { $writer->($_[0], $_[1]) };
25 my ($attr, $reader, $writer) = @_;
26 return sub { $writer->($_[0], $reader->($_[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], abs($reader->($_[0])) ) };
54 # register the alias ...
55 package # hide me from search.cpan.org
56 Moose::Meta::Attribute::Custom::Number;
57 sub register_implementation { 'MooseX::AttributeHelpers::Number' }
65 MooseX::AttributeHelpers::Number
71 use MooseX::AttributeHelpers;
74 metaclass => 'Number',
89 my $real = Real->new();
90 $real->add(5); # same as $real->integer($real->integer + 5);
91 $real->sub(2); # same as $real->integer($real->integer - 2);
95 This provides a simple numeric attribute, which supports most of the
96 basic math operations.
106 =item B<method_constructors>
110 =head1 PROVIDED METHODS
112 It is important to note that all those methods do in place
113 modification of the value stored in the attribute.
117 =item I<set ($value)>
119 Alternate way to set the value.
121 =item I<add ($value)>
123 Adds the current value of the attribute to C<$value>.
125 =item I<sub ($value)>
127 Subtracts the current value of the attribute to C<$value>.
129 =item I<mul ($value)>
131 Multiplies the current value of the attribute to C<$value>.
133 =item I<div ($value)>
135 Divides the current value of the attribute to C<$value>.
137 =item I<mod ($value)>
139 Modulus the current value of the attribute to C<$value>.
143 Sets the current value of the attribute to its absolute value.
149 All complex software has bugs lurking in it, and this module is no
150 exception. If you find a bug please either email me, or add the bug
157 =head1 COPYRIGHT AND LICENSE
159 Copyright 2007-2008 by Infinity Interactive, Inc.
161 L<http://www.iinteractive.com>
163 This library is free software; you can redistribute it and/or modify
164 it under the same terms as Perl itself.