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"?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.