in reply to Re^3: Why reftype and blessed are making my life harder than it needs to be
in thread Why reftype and blessed are making my life harder than it needs to be
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. :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Why reftype and blessed are making my life harder than it needs to be (XS/_reftype)
by dragonchild (Archbishop) on Feb 10, 2006 at 14:13 UTC | |
by demerphq (Chancellor) on Feb 10, 2006 at 14:22 UTC | |
by dragonchild (Archbishop) on Feb 10, 2006 at 14:27 UTC | |
by demerphq (Chancellor) on Feb 10, 2006 at 14:36 UTC | |
by tye (Sage) on Feb 10, 2006 at 15:04 UTC | |
| |
by dragonchild (Archbishop) on Feb 10, 2006 at 14:38 UTC |