* hv@crypt.org <hv@crypt.org> [2009-12-28 12:40]: > FWIW I have copies of this scattered around various codebases: > sub _isa { > my($val, $class) = @_; > eval { $val->can('isa') } > ? $val->isa($class) > : UNIVERSAL::isa($val, $class); > } The `eval` is redundant. If you’re going to use `eval` you can just say this: eval { return $val->isa($class) }; $class eq ref $val; But this is s l o w . What you wou want is this: sub _isa { my ( $val, $class ) = @_; UNIVERSAL::can( $val, 'can' ) ? $val->isa( $class ) : $class eq ref $val; } Here `UNIVERSAL::can( $foo, 'can' )` serves as a no-modules-needed replacement of `Scalar::Util::blessed($foo)`, which is the only acceptable form of using the `UNIVERSAL` methods as functions IMO. > I'd love not to need it any more Ditto. And as you saw (sorry to make an example of you!), most people do not write it very well. :-) Many do not even write it correctly. Having a, well, blessed version of this in core that people could just use instead of reinventing it every time over would greatly reduce the number of bugs lurking in Perl codebases everywhere. > I don't see how to get there from here. Ditto. :-( -- *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1} &Just->another->Perl->hack; #Aristotle Pagaltzis // <http://plasmasturm.org/>Thread Previous | Thread Next