Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Re: Re: How can I find the calling object?

by John M. Dlugosz (Monsignor)
on Nov 20, 2002 at 15:43 UTC ( [id://214490]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: How can I find the calling object?
in thread How can I find the calling object?

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

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

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: How can I find the calling object?
by demerphq (Chancellor) on Nov 20, 2002 at 16:48 UTC
    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....

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://214490]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-29 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found