package MooseX::AttributeHelpers::MethodProvider::Number;
use MooseX::AttributeHelpers::MethodProvider;

our $VERSION   = '0.02';
our $AUTHORITY = 'cpan:STEVAN';

my %o = (add => '+', sub => '-', mul => '*', div => '/', mod => '%');
my %methods = map {my $m = $_; $m => sub {
    my ($attr, $reader, $writer) = @_;
    return eval "sub { \$writer->(\$_[0], \$reader->(\$_[0]) $o{$m} \$_[1]) }";
}} (keys %o);

$methods{abs} = sub {
    my ($attr, $reader, $writer) = @_;
    return sub { $writer->($_[0], CORE::abs($reader->($_[0]))) };
};

$methods{set} = sub {
    my ($attr, $reader, $writer) = @_;
    return sub { $writer->($_[0], $_[1]) };
};

add_method_provider Number => (
    type => 'Num',
    provides => \%methods,
);

1;

__END__

=pod

=head1 NAME

MooseX::AttributeHelpers::MethodProvider::Number

=head1 DESCRIPTION

This is a role which provides the method generators for
L<MooseX::AttributeHelpers::Number>.

=head1 PROVIDED METHODS

All methods but 'set' are plain mathematical operators, as in
C<$current_value = $current_value OP $argument>
where OP is the operator listed next to the method name.

=over 4

=item B<add> +

=item B<sub> -

=item B<mul> *

=item B<div> /

=item B<mod> %

=item B<abs> |$val|, or $val = abs($value).

=item B<set>

A way to set the value instead of 'setter' or 'is => "rw"'.  This method is
provided for convenience.

=back

=head1 BUGS

All complex software has bugs lurking in it, and this module is no
exception. If you find a bug please either email me, or add the bug
to cpan-RT.

=head1 AUTHOR

Paul Driver E<lt>frowith@cpan.orgE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright 2007-2008 by Infinity Interactive, Inc.

L<http://www.iinteractive.com>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut
