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 Moose::Meta::Attribute::Custom::Number;
56 sub register_implementation { 'MooseX::AttributeHelpers::Number' }
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.
103 =item B<method_constructors>
107 =head1 PROVIDED METHODS
109 It is important to note that all those methods do in place
110 modification of the value stored in the attribute.
114 =item I<set ($value)>
116 Alternate way to set the value.
118 =item I<add ($value)>
120 Adds the current value of the attribute to C<$value>.
122 =item I<sub ($value)>
124 Subtracts the current value of the attribute to C<$value>.
126 =item I<mul ($value)>
128 Multiplies the current value of the attribute to C<$value>.
130 =item I<div ($value)>
132 Divides the current value of the attribute to C<$value>.
134 =item I<mod ($value)>
136 Modulus the current value of the attribute to C<$value>.
140 Sets the current value of the attribute to its absolute value.
146 All complex software has bugs lurking in it, and this module is no
147 exception. If you find a bug please either email me, or add the bug
154 =head1 COPYRIGHT AND LICENSE
156 Copyright 2007 by Infinity Interactive, Inc.
158 L<http://www.iinteractive.com>
160 This library is free software; you can redistribute it and/or modify
161 it under the same terms as Perl itself.