in reply to Fixing nits with $object->can($method);

I think that's an interesting idea, but I can see where it might not work when you expect it to. Much like UNIVERSAL::isa, some people may call UNIVERSAL::can directly as a static method so as to avoid having to check if something is an object or package name. Contrived example:

sub has_method { my ( $target, $method ) = @_; return UNIVERSAL::can( $target, $method) ? 1 : 0; }

How often this will occur is hard to say, but it's at least worth a warning in the documentation. Whether it's advisable is entirely another issue -- I generally tend to think that one should realize that modules might override UNIVERSAL functions for a reason and respect that.

-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.

Replies are listed 'Best First'.
Re^2: Fixing nits with $object->can($method);
by chromatic (Archbishop) on Dec 04, 2005 at 22:18 UTC

    People shouldn't do that. The documentation has a warning about that now. Use blessed() from Scalar::Util instead.

    I wrote an entire article about this and other traps in The Perl Review's Winter 2005 edition.