-
package MooseX::AttributeHelpers::MethodProvider::Number;
-use Moose::Role;
+use MooseX::AttributeHelpers::MethodProvider;
our $VERSION = '0.02';
our $AUTHORITY = 'cpan:STEVAN';
-my %ops = (
- add => '+',
- sub => '-',
- mul => '*',
- div => '/',
- mod => '%',
-);
-
-foreach my $method (keys %ops)
-{
- my $s = $ops{$method};
- __PACKAGE__->meta->alias_method($method, sub {
- my ($attr, $reader, $writer) = @_;
- return eval "sub { \$writer->(\$_[0], \$reader->(\$_[0]) $s \$_[1]) }";
- });
-}
+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);
-sub abs : method {
+$methods{abs} = sub {
my ($attr, $reader, $writer) = @_;
return sub { $writer->($_[0], CORE::abs($reader->($_[0]))) };
-}
+};
-sub set : method {
+$methods{set} = sub {
my ($attr, $reader, $writer) = @_;
return sub { $writer->($_[0], $_[1]) };
-}
+};
+
+add_method_provider Number => (
+ type => 'Num',
+ provides => \%methods,
+);
1;
=head1 NAME
MooseX::AttributeHelpers::MethodProvider::Number
-
+
=head1 DESCRIPTION
-This is a role which provides the method generators for
+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
+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.
=head1 BUGS
-All complex software has bugs lurking in it, and this module is no
+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.