Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
We can clearly see 'undef' is being passed and that's what's throwing off your conditional. This is so counter-intuitive that I assume I'm missing something, though a quick scan through the docs doesn't reveal what that would be.
The relevant part of the documentation is:
Calling Conventions for Binary Operations The functions specified in the "use overload ..." direc­ tive are called with three (in one particular case with four, see "Last Resort") arguments. If the corresponding operation is binary, then the first two arguments are the two arguments of the operation. However, due to general object calling conventions, the first argument should always be an object in the package, so in the situation of "7+$a", the order of the arguments is interchanged. It probably does not matter when implementing the addition method, but whether the arguments are reversed is vital to the subtraction method. The method can query this infor­ mation by examining the third argument, which can take three different values: FALSE the order of arguments is as in the current opera­ tion. TRUE the arguments are reversed. "undef" the current operation is an assignment variant (as in "$a+=7"), but the usual function is called instead. This additional information can be used to generate some optimizations. Compare "Calling Conventions for Mutators".
The first argument is the object, no surprise here. Since the stringify operation is a unary operation, the second argument is undefined. The third argument is the empty string, which is false, but defined. And this fits the description of the documentation - the arguments aren't reversed, nor is the operation an assignment variant.

Abigail


In reply to Re: Overloading oddity by Abigail-II
in thread Overloading oddity by theguvnor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-19 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found