in reply to Ironclad protection of instance data

You might want to consider using Abigail-II's inside out object technique.

  • Comment on Re: Ironclad protection of instance data

Replies are listed 'Best First'.
Re^2: Ironclad protection of instance data
by friedo (Prior) on Jul 03, 2004 at 18:33 UTC
    Interesting link, thanks. But I must admit I have no idea what's going on.

    sub set_phrase { my $self = shift; my $phrase = shift; $phrase {$self} = $phrase; } sub get_phrase { my $self = shift; return $phrase {$self}; }
    What does $phrase {$self} do?
      What does $phrase {$self} do?

      It uses the stringified reference at $self as the key for a lexical hash. The hash is unreachable outside of the module, but is shared between all the instances of that object, so you have to key it on something unique. Using the stringified reference is a convenient way to do that.

      Update: just to clarify a bit what I mean by stringified reference:

      $ perl -le 'my $self = {}; print $self' HASH(0x814cc20)

      Something like that would be used as the hash key. Since that contains a memory location, it will be unique (unless something Very Bad happens).

        Ah ha! That's brilliant. I was confused by the space between $phrase and {$self}.

        I think I am going to use a variant of that technique. Thanks for the replies, everyone. (Even those that think it's a bad idea. :) ).