OK, you're saying that if the object overloads stringify, then you won't get the normal string for the hash or array.

Right. Also if it overloads numericification. (Which is worse since there isnt a overload::numval)

But what does parsing the StrVal left of the = sign do that ref() doesn't?

Im not sure where the "left" part comes from. I did a regex to check if an '=' was in the name only to determine that the first parameter passed to the callers sub was indeed a blessed reference. This is a good first step, but it isnt an exhaustive check as it has no way to determine that the following are different

foo($obj); $obj->foo();
If caller had a flag to say that the sub was invioked via a method then this would be a much better way to do this.

Anyway, coming back to parsing.. The result of overload::StrVal() gives three things: Base Type*, memory location/unique identifier, Class type.

Ref gives you the first if the reference isnt blessed and the class name if it is. That isnt particularly useful (in my experience) as you more often than not want to check type to see how the object should be dereferenced.

Also Base Type has a star next to it because it isnt really base type. For instance a reference to a scalar value can return no less than three completely different things: Ref, Scalar and Glob. While apparently weird it is useful behaviour though. :-)

print join("\t",ref(\[]),ref(\"foo"),ref(\*glob),ref(\do{my $x=*fo +o})); # REF SCALAR GLOB GLOB
Cheers,

--- demerphq
my friends call me, usually because I'm late....


In reply to Re: Re: Re: Re: Re: How can I find the calling object? by demerphq
in thread How can I find the calling object? by strider corinth

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.