Interestingly, reftype only checks the length of ref, which is why it can probably be fooled by "\0".
You are looking at the perl implementation, which isn't quite what i would consider to the canonical implementation. IMO the canonical implementation is the XS one:
char * reftype(sv) SV * sv PROTOTYPE: $ CODE: { if (SvMAGICAL(sv)) mg_get(sv); if(!SvROK(sv)) { XSRETURN_UNDEF; } RETVAL = sv_reftype(SvRV(sv),FALSE); } OUTPUT: RETVAL
In Data::Dump::Streamer its implemented as
char * reftype(sv) SV * sv PROTOTYPE: $ CODE: { if (SvMAGICAL(sv)) mg_get(sv); if(!SvROK(sv)) { XSRETURN_NO; } else { RETVAL = sv_reftype(SvRV(sv),FALSE); } } OUTPUT: RETVAL
Notice the only difference is the XSRETURN_NO; versus XSRETURN_UNDEF;. With the benefit of experience IMO the use of XSRETURN_UNDEF; was a mistake. I've said as much on p5p a number of times, but without much response. I guess it would be too dangerous a change, which is why im going to be providing patches to implement _reftype() so you can say
if (_reftype($foo) eq $TYPE) { ... }
without worrying about warnings. Of course if you don't want to wait, you can always
use Data::Dump::Streamer qw(reftype);
And get the more practical implementation Right Now. :-)
In reply to Re^4: Why reftype and blessed are making my life harder than it needs to be (XS/_reftype)
by demerphq
in thread Why reftype and blessed are making my life harder than it needs to be
by dragonchild
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |