in reply to how to find a subroutine exists or not
Update: Ah. This works, but only sort of. See diotalevi's response below, as well as the other posts in the thread.
This should work:
if (my $coderef = __PACKAGE__->can("test")) { $coderef->(); }
Update: it might be worth pointing out that this is equivalent:
if (__PACKAGE__->can("test")) { test(); }
And if you're in the main package, this is as well:
if (main->can("test")) { test(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to find a subroutine exists or not
by diotalevi (Canon) on Apr 20, 2006 at 15:38 UTC | |
|
Re^2: how to find a subroutine exists or not
by mrpeabody (Friar) on Apr 20, 2006 at 16:11 UTC | |
by xdg (Monsignor) on Apr 20, 2006 at 17:21 UTC |