[OT] best way to determine existence of a function in a package

Dan Brook mr.daniel.brook at gmail.com
Mon Nov 19 10:56:42 GMT 2007


On Nov 19, 2007 9:53 AM, Dirk Koopman <djk at tobit.co.uk> wrote:
> The problem:
>
> A user may include a local version of a package which may include one or
>   more local versions of a static function (there are no references,
> blessed or otherwise to ->can() on).
>
> I want to detect whether or not that function is explicitly defined.
>
> if (defined *Local::function) {
>     ...
>     ...
> }
>
> except that expression always returns true, which is rather a nuisance.

Test using the code sigil e.g

  if(defined &Local::function) { ... }

See also, http://perldoc.perl.org/functions/defined.html

Cheers,
Dan


More information about the london.pm mailing list