in reply to How to check if a function exists within a package?

For functions, defined.

if ( defined( &perlmonk::funnyfunction ) )

For methods, can. Checks inheritance.

if ( perlmonk->can('funnyfunction') )
if ( $obj->can('funnyfunction') )

Replies are listed 'Best First'.
Re^2: How to check if a function exists within a package?
by jettero (Monsignor) on Sep 08, 2008 at 02:01 UTC
    if ( defined( &perlmonk::funnyfunction ) )

    Why wouldn't that call the function passing in @_ and check defined on the result? I mean, I see that it doesn't do that, but why? You have to put the ()'s on the end of it to get what I'd expect.

    -Paul

      It's just another special parsing rule. exists and goto are exactly the same, but they are hardly the only three functions that have special parsing rules. map's curlies don't create a hash. print's file handle isn't a function name. And the list goes on.
Re^2: How to check if a function exists within a package?
by rapide (Beadle) on Sep 08, 2008 at 01:38 UTC
    Great answer. Since I had methods it was the right answer to use can. Thanks everyone!