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

chromatic chromatic at wgz.org
Mon Nov 19 17:21:47 GMT 2007


On Monday 19 November 2007 03:16:08 Paul LeoNerd Evans wrote:

> On Mon, 19 Nov 2007 09:53:41 +0000 Dirk Koopman <djk at tobit.co.uk> wrote:
> > 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).
>
> You don't need a reference. I've always found that UNIVERSAL::can() works
> just as well:
>
>   if( my $subref = UNIVERSAL::can( "Package", "function" ) ) {
>      $subref->( args, here );
>   }

That works in the same way that Acme::UNIVERSAL::new works: accidentally, 
occasionally, and certainly not by design.

-- c


More information about the london.pm mailing list