[OT] best way to determine existence of a function in a package
Dirk Koopman
djk at tobit.co.uk
Mon Nov 19 22:53:23 GMT 2007
Tim Sweetman wrote:
> Jonathan Rockway wrote:
>
>> On Mon, 2007-11-19 at 11:16 +0000, Paul LeoNerd Evans wrote:
>>
>>
>>> 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 );
>>> }
>>>
>>>
>>
>> Everyone was quick to jump down your throat on this one, so I thought
>> I'd explain why.
>>
> They're just like that.
>
> "Whenever you want to on AUTOLOAD() its almost always better to create a
> generic method that takes the names you would have autoloaded as an
> extra argument rather than having methods created on the fly" - Damian
> Conway, "Perl Best Practices"
>
Before we go off on one again, could I point that I *specifically*
asked to find out whether a *static* (i.e. not AUTOLOADed) function (not
method) was defined or not in a *static* package.
>>
> How about
>
> Local->can("function")
>
> That'll work, I think, and, as far as I can see, should keep everyone
> happy.
>
Nope, that doesn't work, tried that. (Slightly) interestingly the first
time I tried "defined &Local::bar" and got the "wrong" answer. Hence the
attempt to use *Local::bar. It works now (even in 5005_03) so I am happy.
I *would* like to know "defined *Local::bar" always returns true.
Dirk
More information about the london.pm
mailing list