I was wondering about something. I can check whether a class has a certain method, by calling can, for example,
use Math::Complex;
print "plus is supported\n" if (Math::Complex->can("plus"));
It works. I checked the Math::Complex module, the overloaded “+” actually calls this 'plus' function. Now, is it not normal for me to expect that, the following should work?
use Math::Complex;
print "+ is supported\n" if (Math::Complex->can("+"));
But it does not, even though “+” is overloaded for this class. My question is:
- Did I do something wrong? If yes, then what is the correct syntax to check whether an operator is overloaded?
- If I didn’t do anything wrong, is it not nice for Perl to support a unified interface for checking whether a method, or operator is supported? They are both operations you can apply on a class/object though. Also, you remember those operators by their symbols, for example "+", not by the methods under, for example, if I didn't check the Complex.pm, how can I know that "+" is actually "plus"?