Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: dynamic method creation, dispatch table or pseudo methods?

by LanX (Sage)
on Apr 18, 2021 at 20:33 UTC ( #11131442=note: print w/replies, xml ) Need Help??


in reply to dynamic method creation, dispatch table or pseudo methods?

If providing implementation is part of the API, you might want to have better control about user errors

you could do something like (untested)

sub my_meth { my $self = shift; my $cmd = $self->{api_meth}; unless ( defined $cmd ) { # default } else { eval { $cmd->(@_) } or raise_error(); } }
Of course this will be slower than your suggestions...

TIMTOWTDI and YMMV :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2021-10-18 05:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (72 votes). Check out past polls.

    Notices?