sub safe_isa { my($value, $class) = @_; eval { $value->can('isa') } ? $value->isa($class) : UNIVERSAL::isa($value, $class); }
Note that calling $value->isa($class) directly blows up when $value is not an object, and a ref() check is insufficient to distinguish between blessed and unblessed references.
An alternative approach would use Scalar-List-Utils to replace the eval with: defined(Scalar::Util::blessed($value))
Hugo
|
|---|