in reply to find out method name from the reference
I think (untested) that for perl 5.8 you would need to rewrite the XSub as:use warnings; use strict; use Inline C => <<'EOC'; SV * test (CV * x, char * name) { if(x == get_cv(name, 0)) return newSVuv(1); return newSVuv(0); } EOC package Foo; sub bar {}; package main; my $coderef = \&Foo::bar; my $null; print test($coderef, "Foo::bar"), "\n"; # 1 print test($coderef, "Foo::Bar"), "\n"; # 0 print test($null, "Foo::Bar"), "\n"; # dies appropriately
I don't know about the wisdom of using that approach - and there's quite possibly a better solution anyway.SV * test (SV * x, char * name) { if((CV*)SvRV(x) == get_cv(name, 0)) return newSVuv(1); return newSVuv(0); }
But first make sure it *is* a code reference that you're passing. Better still, just use B; as betterworld suggests.SV * foo1(SV * x) { return newSVpv(HvNAME(CvSTASH((CV*)SvRV(x))), 0); }
|
|---|