Composite now implemented.
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / MethodProvider / Number.pm
CommitLineData
667db0bf 1package MooseX::AttributeHelpers::MethodProvider::Number;
786dbc3d 2use MooseX::AttributeHelpers::MethodProvider;
667db0bf 3
4our $VERSION = '0.02';
5our $AUTHORITY = 'cpan:STEVAN';
6
786dbc3d 7my %o = (add => '+', sub => '-', mul => '*', div => '/', mod => '%');
8my %methods = map {my $m = $_; $m => sub {
9 my ($attr, $reader, $writer) = @_;
10 return eval "sub { \$writer->(\$_[0], \$reader->(\$_[0]) $o{$m} \$_[1]) }";
11}} (keys %o);
667db0bf 12
786dbc3d 13$methods{abs} = sub {
667db0bf 14 my ($attr, $reader, $writer) = @_;
15 return sub { $writer->($_[0], CORE::abs($reader->($_[0]))) };
786dbc3d 16};
667db0bf 17
786dbc3d 18$methods{set} = sub {
667db0bf 19 my ($attr, $reader, $writer) = @_;
20 return sub { $writer->($_[0], $_[1]) };
786dbc3d 21};
22
23add_method_provider Number => (
24 type => 'Num',
25 provides => \%methods,
26);
667db0bf 27
281;
29
30__END__
31
32=pod
33
34=head1 NAME
35
36MooseX::AttributeHelpers::MethodProvider::Number
786dbc3d 37
667db0bf 38=head1 DESCRIPTION
39
786dbc3d 40This is a role which provides the method generators for
667db0bf 41L<MooseX::AttributeHelpers::Number>.
42
43=head1 PROVIDED METHODS
44
786dbc3d 45All methods but 'set' are plain mathematical operators, as in
720fa35b 46C<$current_value = $current_value OP $argument>
47where OP is the operator listed next to the method name.
667db0bf 48
49=over 4
50
720fa35b 51=item B<add> +
667db0bf 52
720fa35b 53=item B<sub> -
667db0bf 54
720fa35b 55=item B<mul> *
667db0bf 56
720fa35b 57=item B<div> /
667db0bf 58
720fa35b 59=item B<mod> %
667db0bf 60
720fa35b 61=item B<abs> |$val|, or $val = abs($value).
667db0bf 62
720fa35b 63=item B<set>
667db0bf 64
65A way to set the value instead of 'setter' or 'is => "rw"'. This method is
66provided for convenience.
67
68=back
69
70=head1 BUGS
71
786dbc3d 72All complex software has bugs lurking in it, and this module is no
667db0bf 73exception. If you find a bug please either email me, or add the bug
74to cpan-RT.
75
76=head1 AUTHOR
77
78Paul Driver E<lt>frowith@cpan.orgE<gt>
79
80=head1 COPYRIGHT AND LICENSE
81
82Copyright 2007-2008 by Infinity Interactive, Inc.
83
84L<http://www.iinteractive.com>
85
86This library is free software; you can redistribute it and/or modify
87it under the same terms as Perl itself.
88
89=cut