This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make Internals::SvREADONLY smarter
authorFather Chrysostomos <sprout@cpan.org>
Tue, 12 Jul 2011 18:54:15 +0000 (11:54 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 12 Jul 2011 20:00:03 +0000 (13:00 -0700)
commit3e89ba198c1cf083986263bd013ce43b4f206692
tree51f85610ab3837a02b03c0f30a3b8a066ab0a2f0
parentfa819c1ce3252e7ae97e9cdd4d3d0dd1edb06fa1
Make Internals::SvREADONLY smarter

(aka: More fun with Hash::Util)

$ perl -lMHash::Util=lock_value
$h{a} = __PACKAGE__; lock_value %h, a; $h{a} = "3"; print $h{a}'
^D
3

OK, so it didn’t really lock it. Now for more fun:

$ perl -lMHash::Util=unlock_value
$h{a} = __PACKAGE__; unlock_value %h, a; $h{a} =~ y/ia/ao/;
print __PACKAGE__
^D
moan

There are three different ways to fix this:
1) Add an SvFAKE function to Internals:: (not *more* ‘internals’ for
   people [ahem, Const::Fast, ahem] to abuse!)
2) Use B::* functions in Hash::Util to check the flags (too slow)
3) Make Internals::SvREADONLY less ‘internal’, by having it deal with
   readonliness in general, rather than just the SVf_READONLY flag.

The third approach seems the most logical, so that’s what this
commit does.

There is one test in t/op/tr.t that uses Internals::SvREADONLY to
detect bovinity, so I’ve changed it to use B instead, as that will
have no effect on post-install efficiency.

(This approach also fixes Const::Fast’s bugginess, but that is purely
accidental.)
t/lib/universal.t
t/op/tr.t
universal.c