Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Checking if a subroutine has been defined in a package...

by pjf (Curate)
on Oct 13, 2001 at 18:44 UTC ( #118664=note: print w/ replies, xml ) Need Help??


in reply to Re: Checking if a subroutine has been defined in a package...
in thread Checking if a subroutine has been defined in a package...

G'day dragonchild,

What your code is doing is calling the subroutine "$package::$funcName", and checking if it returns a defined value. This is certainly not what you want to be doing, because if the subroutine does not exist, you end up with a fatal errror.

If your subroutine does exist, you've just invoked it with no arguments, and it could return undef just to spite you anyway.

Rather than calling the subroutine, you instead want to use globs to access perl's symbol table. This is described in my reply above. It also happens to be a bit faster than methods using can(), since inheritance is not checked.

Cheers,
Paul


Comment on Re: Re: Checking if a subroutine has been defined in a package...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://118664]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2014-07-29 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (228 votes), past polls