In reading the "overload" manpage again, I realized that it attempts to define the comparison operators based on "cmp" operator if they are not there. (Or is supposed to, though some of my tests on the subroutine below show that it fails if not all of the comparisons are defined.)


On 14/11/2004 09:21 Robert Rothenberg wrote:

So I have an idea for a module called "Class::Stringify" that would do the following as a base class for a module:
(1) if the class doesn't have the stringification operator overloaded, die
since it's the bare minimum
(2) if the class doesn't have the cmp operator overloaded, define it using
the stringification operator: "$a" cmp "$b"
(3) if the class doesn't have the eq, ne, le, lt, ge, gt operators overloaded,
define them using the cmp operator


There are some variations on this where a class might have lt (or gt) and eq (or ne) defined which can be used to define cmp and the others. And I'm guessing that with some thought I could come up with a smart way to define the operations that need to be defined.




Reply via email to