I'm working on a project and am trying to settle on some API details. Currently, it is how users will check a value, such as a response code, set by the invocation of a method on an object, where the value is from a small set of possibilities. Actually checking the response code wouldn't need to be done very often unless testing or debugging. But even calls that die will set a response code, so if the die was captured by eval you could interrogate for more information. Etc. So for example, if the object was $client and you had just invoked method foo on it: $client->foo({some => 'args'}); And you wanted to see the specific response code, what might be the most 'natural' syntax? Here are the possibilities I'm considering:
Initially I had a sub-package that exported all the relevant constants, such as OK. However, I have some other message handling methods that would be useful to most of the packages in the set and would just as well make a simple base class. Options 1 & 2 above both require exporting the constants, which doesn't seem to be compatible with use base qw();. Options 3 & 4 work when the class for $client inherits from the messaging base class (which sets the constants internally), but the use of $client twice looks a bit odd to me. Option 5 would remove the need for constants, but it also looks a bit odd to me to be sending a word as a string to check the status - but that could be just be because I'm used to using the constants.
Fellow Monks, what would you prefer to use? Do you have an idea that might be better? And yes, please feel free to include a link to your personal favorite message passing or exception handling module whose interface you like or that you think I should consider using directly to solve my problem. ;)
In reply to OOP style question: Checking a value by spq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |