in reply to Re: Re: Is reference blessed?
in thread Is reference blessed?
The problem with just UNIVERSAL::can($ref,'isa') is that it can return a true value when $ref isn't even a reference. So you really have to make multiple tests:
or just:if( ! ref($r) ) { # no reference at all } elsif( ! UNIVERSAL::can($r,'can') ) { # unblessed ref } else { # blessed ref }
orif( ref($r) && UNIVERSAL::can($r,'can') ) { # blessed ref }
and I can't make a convincing case for one style over the other at the moment.if( ref($r) && eval { $r->can('can') } ) { # blessed ref }
And, yes, it would be nice if there were less overloaded versions of these things so that blessed returned the package that a reference was blessed into and ref just always returned the type of thing. That was a certainly a design mistake IMO.
- tye (but my friends call me "Tye")
|
---|