develooper Front page | perl.perl5.porters | Postings from August 2001

Re: [PATCH for discussion] clamp, round #2

Thread Previous | Thread Next
Jeffrey Friedl
August 1, 2001 05:32
Re: [PATCH for discussion] clamp, round #2
Message ID:

Nick Ing-Simmons <> wrote:
|> I seem to be missing something here. I agree they are orthogonal, and need 
|> more than one bit. I am proposing that a "read only hash with N members"
|> uses N+1 bits and a "clamped hash" uses 1 bit - thus:
|> A. Setting "the" bit on the HV to say "keys are fixed" (i.e. clamp).
|> B. Setting "the" bit on the SVs that are the values to say "cannot change value".

This is exactly what my patch does.

Clamp::Keys(%hash) does "A" above.
Readonly::Hash(%hash) does both "A" and "B".
If you wish to do "B" only, one may with each() and Readonly::Set($hash{$key})

SvREADONLY, and only SvREADONLY, is used for the above.

What I referred to as orthoginal in the implementation (although to the
user, quite related) is the ability to do Clamp::Access(), which causes
access to non-existant/unapproved keys to be an error. It's this flag on
the HV that requires another bit.

The separate actions of clamping access and clamping keys are described in
the docs, although obviously not well enough. At least I made sure to put
the docs at the head of the patch:

(To my credit, I did disclaimer the user-visible aspect of the implementation
as being just an example)

|> Then explain why this cannot be done with 'magic' ;-)

I made my position on magic clear in the note to which you replied:

Maybe it's that clarity that accounts for your ";-)", but in case you
really want the explaination, I'll reiterate (cool -- I've used that word
twice now in a week):

   "I still need to be educated about magic types, etc.. "

BTW, I was talking to Jeremy Zawodny and he thought that since global symbol
tables are hashes, one could clamp keys/access to a package, which would
then catch stuff like
        if ($Some::Package::Quite)
when one meant
        if ($Some::Package::Quite)

This currently doesn't work because of my aformentioned ignorance of
magicness (and %:: is magic), but the concept is wonderful.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About