1
package Data::Perl::Role::Number;
2
$Data::Perl::Role::Number::VERSION = '0.002008';
3
# ABSTRACT: Wrapping class for Perl scalar numbers.
9
sub new { bless \(my $n = $_[1]), $_[0] }
11
sub add { ${$_[0]} = ${$_[0]} + $_[1] }
13
sub sub { ${$_[0]} = ${$_[0]} - $_[1] }
15
sub mul { ${$_[0]} = ${$_[0]} * $_[1] }
17
sub div { ${$_[0]} = ${$_[0]} / $_[1] }
19
sub mod { ${$_[0]} = ${$_[0]} % $_[1] }
21
sub abs { ${$_[0]} = abs(${$_[0]}) }
31
Data::Perl::Role::Number - Wrapping class for Perl scalar numbers.
39
use Data::Perl qw/number/;
41
my $num = number(123);
43
$num->add(5); # $num == 128
45
$num->div(2); # $num == 64
49
This class provides a wrapper and methods for interacting with scalar strings.
51
=head1 PROVIDED METHODS
53
All of these methods modify the attribute's value in place. All methods return
60
Constructs a new Data::Perl::Collection::Number object initialized with the passed
61
in value, and returns it.
63
=item * B<add($value)>
65
Adds the current value of the attribute to C<$value>.
67
=item * B<sub($value)>
69
Subtracts C<$value> from the current value of the attribute.
71
=item * B<mul($value)>
73
Multiplies the current value of the attribute by C<$value>.
75
=item * B<div($value)>
77
Divides the current value of the attribute by C<$value>.
79
=item * B<mod($value)>
81
Returns the current value of the attribute modulo C<$value>.
85
Sets the current value of the attribute to its absolute value.
95
=item * L<MooX::HandlesVia>
101
Matthew Phillips <mattp@cpan.org>
103
=head1 COPYRIGHT AND LICENSE
105
This software is copyright (c) 2014 by Matthew Phillips <mattp@cpan.org>.
107
This is free software; you can redistribute it and/or modify it under
108
the same terms as the Perl 5 programming language system itself.