in reply to Calling a subroutine via multiple dereferences.

My $0.02 is your code is too complex. Break it down into more than one hash with descriptive names. Why are you using Scalar::Util's refaddr, by the way, it's very unusual and will give different results on different platforms. Why not hash $self itself, won't you get different keys from its stringification?

SSF

  • Comment on Re: Calling a subroutine via multiple dereferences.

Replies are listed 'Best First'.
Re^2: Calling a subroutine via multiple dereferences.
by jethro (Monsignor) on Nov 04, 2008 at 14:56 UTC

      scalar() may not be unique, and may change over the lifetime of the object. For instance, in this case, I've got the scalar conversion overloaded to return the class name and some basic info on the state of the class. Useful for debugging and error returns. However it is quite easy to set up two different objects so that they appear the same. Also, calling one of a few different methods will change what would be returned. (Which leads to a self-referential loop: To get the scalar value, you have to know the scalar value...)

      refaddr() by contrast is stable: The object will always be in a particular location, until it is no longer that object. And no two objects may have the same location at the same time. So it is much safer to use. I don't actually care what the key is, as long as it is unique and stable, and refaddr provides that.

      As for complex... Past the inside-out object, it's just an array of arrays, and the second level array is just to keep things associated. I actually looked at setting up two different arrays, but this is much simpler to keep track of.