Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Test if a string is a sub name

by SankoR (Prior)
on Oct 06, 2022 at 00:39 UTC ( [id://11147270]=note: print w/replies, xml ) Need Help??


in reply to Test if a string is a sub name

I would use can for this. That way, whether your filters inherit functions from parents or import them, your query will work correctly.

sub My::Filters::known { } sub My::Filters::forward; for my $string (qw[known unknown forward]) { warn $string if My::Filters->can($string); }
As a bonus, you can define the package with a variable with can:

sub My::Filters::known { } sub My::Filters::forward; sub My::Other::Filters::forward; for my $package (qw[My::Filters My::Other::Filters]) { for my $func (qw[known unknown forward]) { warn $package . '::' . $func if $package->can($func); } }

Replies are listed 'Best First'.
Re^2: Test if a string is a sub name
by clscott (Friar) on Oct 06, 2022 at 12:41 UTC
    Thanks for this answer, I'll try this out as well
    --
    Clayton

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11147270]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-20 04:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found