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>
109 All complex software has bugs lurking in it, and this module is no
110 exception. If you find a bug please either email me, or add the bug
117 =head1 COPYRIGHT AND LICENSE
119 Copyright 2007 by Infinity Interactive, Inc.
121 L<http://www.iinteractive.com>
123 This library is free software; you can redistribute it and/or modify
124 it under the same terms as Perl itself.