Skip Menu |

This queue is for tickets about the Text-Number CPAN distribution.

Report information
The Basics
Id: 11605
Status: new
Priority: 0/
Queue: Text-Number

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Text::Number won't play nice with other overloaded numbers
In your code, you have: my $value = value($number_1) + value($number_2); value() is defined as: my $self = shift(@_); if (ref($self)) { (@_) and $self->[VALUE] = $_[0]; return $self->[VALUE]; } else { return $self; }; This assumes that anything passed in is going to be either a number or a member of your class. However, this doesn't take into account that I might use Text::Number and add it to an object that also overloads the numeric overloads. Much better would be: sub value { Scalar::Util::blessed( $_[0] ) ? ($_[0] + 0) : ref( $_[0] ) ? die("Why is a simple reference being passed in?") : $_[0] } This requires the use of a specific numify() method that '0+' is mapped to, other than value(). (Otherwise, you end up with an infinite recursive loop of value() calling value().) That numify(), however, can assume that you are definitely your class, so it can be defined as: sub numify { $_[0][VALUE] } The choice of names is arbitrary.