in reply to Calling instance methods with the method name stored in a variable
Does your design really depend on letting your User input the name of the function that needs to be performed? Or, it the name computed from input provided by the User? How are you planning to handle the typo problem? (And please tell me you aren't going to use autoload() to resolve the unknown name.)
Before I went down the path of using variables as names, I would take a few minutes and review the 'logic' that is requiring these measures. If you can't get out of the box, then stick in a block of comments explaining why things are as they are; make sure that the code that vets out the content of your variable is bullet-proof; and stick the call inside an eval() block. And don't be surprised when the block fails every so often on 'function unknown'.
I'd still go back to the designer and look at them over the tops of my glasses....
Update (after another cuppa)
The more I consider your question, the more it sounds you are writing a wrapper for a library that uses function-signatures in the dispatch process (C++ and it's propensity to mangle names comes forcibly to mind). If this is the case, please revisit the design decision that mandates the wrapper in Perl. You might be better served (and your Maintenance Programmers will be less likely to use your name as a swear-word) agreeing to use a common language, even it it means rewriting the Library in Perl.
As an aside, I am horribly curious to know about the application that brought about the original question. It sounds like Fun, in a perverse sense of the word.
----
I Go Back to Sleep, Now.
OGB
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Calling instance methods with the method name stored in a variable
by Cybris (Sexton) on Jun 05, 2009 at 07:45 UTC |