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.
use ExtUtils::testlib;
use Flag; #all local, sorry
my $c = 'test';
Flag::sv_set_flag($c, 'READONLY');
#$c++;
#$c = 'not a test';
$c = 5;
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 Devel::Peek;
use ExtUtils::testlib;
use Flag;
my $c = 15;
Flag::sv_set_flag($c, 'READONLY');
print Dump $c;
print "$c";
print Dump $c;
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.
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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|