1 package Moose::Meta::Attribute::Native::Trait::Number;
5 $VERSION = eval $VERSION;
6 our $AUTHORITY = 'cpan:STEVAN';
8 with 'Moose::Meta::Attribute::Native::Trait';
10 sub _helper_type { 'Num' }
12 # NOTE: we don't use the method provider for this module since many of
13 # the names of the provided methods would conflict with keywords - SL
15 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] ) ) ) };
61 Moose::Meta::Attribute::Native::Trait::Number - Helper trait for Num attributes
84 my $real = Real->new();
85 $real->add(5); # same as $real->integer($real->integer + 5);
86 $real->sub(2); # same as $real->integer($real->integer - 2);
90 This provides a simple numeric attribute, which supports most of the
91 basic math operations.
93 =head1 PROVIDED METHODS
95 It is important to note that all those methods do in place modification of the
96 value stored in the attribute. These methods are implemented within this
103 Alternate way to set the value.
107 Adds the current value of the attribute to C<$value>.
111 Subtracts C<$value> from the current value of the attribute.
115 Multiplies the current value of the attribute by C<$value>.
119 Divides the current value of the attribute by C<$value>.
123 Returns the current value of the attribute modulo C<$value>.
127 Sets the current value of the attribute to its absolute value.
137 =item B<method_constructors>
143 All complex software has bugs lurking in it, and this module is no
144 exception. If you find a bug please either email me, or add the bug
151 =head1 COPYRIGHT AND LICENSE
153 Copyright 2007-2009 by Infinity Interactive, Inc.
155 L<http://www.iinteractive.com>
157 This library is free software; you can redistribute it and/or modify
158 it under the same terms as Perl itself.