1 package MooseX::AttributeHelpers::Number;
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
8 extends 'MooseX::AttributeHelpers::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' => (
22 my ($attr, $reader, $writer) = @_;
23 return sub { $writer->($_[0], $_[1]) };
26 my ($attr, $reader, $writer) = @_;
27 return sub { $writer->($_[0], $reader->($_[0]) + $_[1]) };
30 my ($attr, $reader, $writer) = @_;
31 return sub { $writer->($_[0], $reader->($_[0]) - $_[1]) };
34 my ($attr, $reader, $writer) = @_;
35 return sub { $writer->($_[0], $reader->($_[0]) * $_[1]) };
38 my ($attr, $reader, $writer) = @_;
39 return sub { $writer->($_[0], $reader->($_[0]) / $_[1]) };
42 my ($attr, $reader, $writer) = @_;
43 return sub { $writer->($_[0], $reader->($_[0]) % $_[1]) };
46 my ($attr, $reader, $writer) = @_;
47 return sub { $writer->($_[0], abs($reader->($_[0])) ) };
55 # register the alias ...
56 package # hide me from search.cpan.org
57 Moose::Meta::Attribute::Custom::Number;
58 sub register_implementation { 'MooseX::AttributeHelpers::Number' }
66 MooseX::AttributeHelpers::Number
72 use MooseX::AttributeHelpers;
75 metaclass => 'Number',
90 my $real = Real->new();
91 $real->add(5); # same as $real->integer($real->integer + 5);
92 $real->sub(2); # same as $real->integer($real->integer - 2);
96 This provides a simple numeric attribute, which supports most of the
97 basic math operations.
107 =item B<method_constructors>
111 =head1 PROVIDED METHODS
113 It is important to note that all those methods do in place
114 modification of the value stored in the attribute.
118 =item I<set ($value)>
120 Alternate way to set the value.
122 =item I<add ($value)>
124 Adds the current value of the attribute to C<$value>.
126 =item I<sub ($value)>
128 Subtracts the current value of the attribute to C<$value>.
130 =item I<mul ($value)>
132 Multiplies the current value of the attribute to C<$value>.
134 =item I<div ($value)>
136 Divides the current value of the attribute to C<$value>.
138 =item I<mod ($value)>
140 Modulus the current value of the attribute to C<$value>.
144 Sets the current value of the attribute to its absolute value.
150 All complex software has bugs lurking in it, and this module is no
151 exception. If you find a bug please either email me, or add the bug
158 =head1 COPYRIGHT AND LICENSE
160 Copyright 2007-2008 by Infinity Interactive, Inc.
162 L<http://www.iinteractive.com>
164 This library is free software; you can redistribute it and/or modify
165 it under the same terms as Perl itself.