1 package MooseX::AttributeHelpers::MethodProvider::Number;
2 use MooseX::AttributeHelpers::MethodProvider;
5 our $AUTHORITY = 'cpan:STEVAN';
7 my %o = (add => '+', sub => '-', mul => '*', div => '/', mod => '%');
8 my %methods = map {my $m = $_; $m => sub {
9 my ($attr, $reader, $writer) = @_;
10 return eval "sub { \$writer->(\$_[0], \$reader->(\$_[0]) $o{$m} \$_[1]) }";
14 my ($attr, $reader, $writer) = @_;
15 return sub { $writer->($_[0], CORE::abs($reader->($_[0]))) };
19 my ($attr, $reader, $writer) = @_;
20 return sub { $writer->($_[0], $_[1]) };
23 add_method_provider Number => (
25 provides => \%methods,
36 MooseX::AttributeHelpers::MethodProvider::Number
40 This module provides the method factories for
41 L<MooseX::AttributeHelpers::Number>.
43 =head1 PROVIDED METHODS
45 All methods but 'set' are plain mathematical operators, as in
46 C<$current_value = $current_value OP $argument>
47 where OP is the operator listed next to the method name.
61 =item B<abs> |$val|, or $val = abs($value).
65 A way to set the value instead of C<setter> or C<is => 'rw'>. This method is
66 provided for convenience.
72 All complex software has bugs lurking in it, and this module is no
73 exception. If you find a bug please either email me, or add the bug
78 Paul Driver E<lt>frodwith@cpan.orgE<gt>
80 =head1 COPYRIGHT AND LICENSE
82 Copyright 2007-2008 by Infinity Interactive, Inc.
84 L<http://www.iinteractive.com>
86 This library is free software; you can redistribute it and/or modify
87 it under the same terms as Perl itself.