in reply to Reliability of SvREADONLY
I am not quite sure why it is said above that type coercion is going to cause a problem here. Let me provide a little example.
Any of those examples produce a "Modification of a read-only value" error. Naturally. And as long as that works, that we cannot directly modify the value, we're set. Certain types of behavior can modify the underlying data structure, but not to the point of changing the eventual data.use ExtUtils::testlib; use Flag; #all local, sorry my $c = 'test'; Flag::sv_set_flag($c, 'READONLY'); #$c++; #$c = 'not a test'; $c = 5;
Naturally the interpolation causes the IV to become an PVIV. But our PV value will be "15"\0. So in any circumstance our behavior is normal. Yes the structure has changed, but from a user standpoint our data is readonly.use Devel::Peek; use ExtUtils::testlib; use Flag; my $c = 15; Flag::sv_set_flag($c, 'READONLY'); print Dump $c; print "$c"; print Dump $c;
Is there a specific need to protect the data from perl internals that could possibly be ignoring the readonly state of a variable? If not, then type coercion isn't a problem at all.