in reply to Re: 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

Thank you! I completely missed that inequivalence. I've changed that test to now read:
my $is_class = eval { $thing->isa( 'Some::Class' ) }; my $is_blah = $is_class && $x == 3;
As for the reftype one ... I wonder if reftype can legally be anything other than GLOB/IO/ARRAY/HASH/CODE/REF/SCALAR? Meaning, q{} cannot legally be returned from reftype().

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
  • Comment on Re^2: Why reftype and blessed are making my life harder than it needs to be
  • Download Code

Replies are listed 'Best First'.
Re^3: Why reftype and blessed are making my life harder than it needs to be
by xdg (Monsignor) on Feb 09, 2006 at 22:48 UTC

    Reading the code for it, it looks like it can't return q{}. If ref returns the empty string, reftype returns undef. Otherwise, it looks like it gives one of the underlying types. Looks like blessing into the empty string will still slip past reftype. (Bug or feature? You make the call...)

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      So, should there be a patch to reftype() so that it returns one(qw{HASH ARRAY SCALAR CODE GLOB IO REF}) or the empty string?

      Why is reftype() even checking ref() in the first place ... reftype() is supposed to return the underlying representation, not the classname. I thought that's what blessed() is for.


      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?