Skip to content

Instantly share code, notes, and snippets.

@atoomic
Forked from dur-randir/mg_overload_table.pl
Created May 24, 2017 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atoomic/2c97fbe70e86896c0ae123db2f1e3493 to your computer and use it in GitHub Desktop.
Save atoomic/2c97fbe70e86896c0ae123db2f1e3493 to your computer and use it in GitHub Desktop.
package Z;
use Devel::Peek ();
use overload "+"=>sub {42};
die "fail" unless 42 == bless({}) + 1;
Devel::Peek::Dump \%Z::;
use Inline C => <<END;
void foo(SV* targ) {
if (!SvOK(targ)) return;
if (SvROK(targ)) targ = SvRV(targ);
if (SvMAGICAL(targ) && mg_find(targ, PERL_MAGIC_overload_table)) {
warn("sv_unmagic");
sv_unmagic(targ, PERL_MAGIC_overload_table);
}
}
END
foo(\%Z::);
Devel::Peek::Dump \%Z::;
die "fail" unless 42 == bless({}) + 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment