in reply to Re: Inside-out classes structure
in thread Inside-out classes structure

In A Scalar::Util::refaddr Oddity, I discussed a failure mode of pure-perl refaddr($), and ambrus pointed out another in his reply to that node.

  1. An unblessed reference becomes blessed when refaddr($) is called on it.
  2. A reference to a literal constant causes refaddr($) to die with a "Modification of constant" error.

A proposed fix:

sub refaddr($) { my $pkg = ref($_[0]) or return; my $is_object = Scalar::Util::blessed($_[0]); bless $_[0], 'Scalar::Util::Fake' if $is_object; my $i = int($_[0]); bless $_[0], $pkg if $is_object; $i; }
That probably works for anything. I hedge that statement a little because some XS wizard might find a way to bless a literal constant.

After Compline,
Zaxo