[OT] best way to determine existence of a function in a package
Tim Sweetman
ti at lemonia.org
Mon Nov 19 22:21:06 GMT 2007
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"
http://www.perlmonks.org/?node_id=342804 # long discussion here
Also
http://template-toolkit.org/pipermail/templates/2007-June/009471.html
> Consider this case:
>
> package My::Module;
> our $AUTOLOAD;
> sub AUTOLOAD { return 42 if $AUTOLOAD =~ /forty_?two/ }
>
>
How about
Local->can("function")
That'll work, I think, and, as far as I can see, should keep everyone happy.
ti'
More information about the london.pm
mailing list