in reply to Re: if (UNIVERSAL::isa($r, ref $l))
in thread if (UNIVERSAL::isa($r, ref $l))
Regarding the $a + $b vs $b + $a issue... Overload handles this transparently.
Lets say that $a is a Number::Fraction and leave $b alone for moment. If we say $c = $a + $b this will be magically transformed to $c=$a->add($b,0); But when we say $c= $b + $a there is only one circumstance where it will not get transformed to $c=$a->add($b,1) and thats when $b is both blessed, and has also overriden addition itself. In the latter case it gets transformed into $b->add($a,0) assuming of course the method in the other package is called 'add' as well.
This is quite unfortunate. $b might "bea" $a, but unless they're of the same class, $a won't "bea" $b.
The point of this node is to show that unless $b is also overriden your comment cant be true. And if $b is overriden then it had better have its own logic to handle the situation properly.
I do however agree with you and the OP that there is a problem here with inheriting the add method. It just wont work right in the child classes. But unless davorg had inheritance in mind I dont think its entirely wrong. Mostly maybe....
|
|---|