This will appear in 5.7.3's Scalar::Util module (if all goes well).
/* yes, this is C code... specifically, this is XS code! this is japhy's first XS work! it implements curse(), which takes an object and makes it not an object. */ #ifdef __cplusplus extern "C" { #endif #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #ifdef __cplusplus } #endif MODULE = Scalar::Curse PACKAGE = Scalar::Curse int curse(obj) SV *obj CODE: if (SvOBJECT(SvRV(obj))) { SvOBJECT_off(SvRV(obj)); SvSTASH(SvRV(obj)) = NULL; RETVAL = 1; } else { RETVAL = 0; } OUTPUT: RETVAL

Replies are listed 'Best First'.
Re: From a Blessing to a Curse
by bikeNomad (Priest) on Jul 15, 2001 at 01:58 UTC
    Congrats on contributing to the core!

    If others want to use this in their own Perl programs now, they could use Inline:

    use Inline C => <<EOF; int curse( SV *obj ) { if (SvOBJECT(SvRV(obj))) { SvOBJECT_off(SvRV(obj)); SvSTASH(SvRV(obj)) = NULL; return 1; } return 0; } EOF my $a = bless {}, 'A'; print ref($a), "\n"; curse($a); print ref($a), "\n";

    update: added clarification and congrats

      Yes, yes, I know I could have used Inline here, but all the rest of the Perl-in-C code for the core is currently written using XS, so I figured I should. It was a simple enough task.

      japhy -- Perl and Regex Hacker
Re: From a Blessing to a Curse
by dragonchild (Archbishop) on Sep 06, 2001 at 22:57 UTC
    That's really cool, japhy. I'm just curious what this would be used for?

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.