Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, here's an XS question this time regarding read-only variables...

In one of my "classes" my blessed thingy happens to be an HV which hold information about a distinguished name (canonical format, abbreviated, surname, given, common name, etc...).

i.e: print $name->{Common};

I'd like to be able to make that hash read-only and tried it (using SvREADONLY_on(HV)) but you can still do this:

$name->{valueNotInHashInitially} = "Some Value";

You can do that even though Devel::Peek show the hash as having the READONLY flag. I did set all the entries (SVs) in the hash to READONLY and that worked.

ie: $name->{Common} = "New Value"; raises an error and dies.

Is there anything I can do so Perl also raise the same error when a user tries to create new entries in my ReadOnly hash?


Christian Cloutier