in reply to A Not-as-Clumsy OOP Implementation?

You might want to not use the Function package that way. Better would be to put your code refs in a hash. Then you can just eval the hash value, instead of using $ref->(). That's very bad to do when $ref is being set by input! Also, why are you adding functions that have to already be in the namespace? They're already there, you don't add them to anything, just call them. What I use for something similiar is an array of hashes, the hashes containing name, regex, and code entries. Then I can loop through the array, test each regex against the input, and execute the code if it matches. Also, I can just add a hash ref to plug in a function, no need to mess with the namespace at runtime.

But that is all that is gained by all that, being able to plug in extra parsers without restarting. Usually that's not needed... I usually only do it in the case of network bots that have to interact with users. Generally, it's best to just stick to the exact methodologies used in the "perltoot" Perl documentation. If you don't see it in there, it's probably a sign to rethink the implementation.

Another important thing is, I don't see a use strict or a use warnings. Probably you just trimmed that part to make your post concise, but you need to include those so we know that you're not just digging holes for yourself. Without strict mode and warnings, there is no salvation.

  • Comment on Re: A Not-as-Clumsy OOP Implementation?