On 6/15/05, Mark Jason Dominus <[EMAIL PROTECTED]> wrote: > > > The attached patch rephrases three pieces of Perl documentation which > > suggest that calling UNIVERSAL::isa() or UNIVERSAL::can() directly is a > > good idea. The revised version explains why it's a bad idea and gives > > more correct recommendations. > > You seem to have removed all mentions of use of UNIVERSAL::isa($x, > 'HASH') without either introducing any equivalent replacement or > indicating any valid reason why it would be a bad idea. > > This use of UNIVERSAL::isa is essentially orthogonal to the other > uses; I think it makes sense to leave it in and document it separately.
Chromatic parenthetically mentioned the replacement for this usage didn't he? I would have thought that Scalar::Util::reftype() is the prefered way to do this. (1) Using UNIVERSAL::isa() is IMO bad as its suseptible to my $obj=bless [],'HASH'; type nonsense. Having said that, neither reftype() nor UNIVERSAL::isa() suffice when you consider that most times what you want to know is whether the object is capable of being dereferenced as a hash. To do that properly you need to use overload::Overloaded() in combination with one of the other methods. Maybe this subject deserves a bigger discussion in the docs? yves (1) IMO its a bummer that reftype returns undef for non references as if it were Pl_sv_no you could say if (reftype($foo) eq 'HASH') { ... } without dealing with warnings. As it is you have to say if (ref $foo and reftype($foo) eq 'HASH') { ... } which is a bit annoying. -- perl -Mre=debug -e "/just|another|perl|hacker/"