| [reply] |
That makes sense, thought the syntax of creating your hash must get a bit messy unusual if you have large and/or many subs. Only a bit though.
I was just thinking about how you would handle modularising the functionality, in terms of the source code rather than semantically?
I probably haven't thought this through properly yet, but to try and explain what I mean, say your writing an editor. The dispatch table is used to invoke actions depending upon user input. The user input can take the form of keystrokes, mouse gestures, CLI comands and possibly menus. Ignoring for the moment any problems that might arise from storing/translating keystroke or mouse gesture info into a hash key. It makes a certain amount of sense to segregate the functionality along those lines into seperate modules, if only for ease of editing. I realise that the segregation would more likely be on the basis of different criteria (eg. edit action on current file, configuration action on current file, global configuration action etc.)
The point is, once you have sub code in different source files, how would you go about building this into a dispatch hash for use in the main input queue processing loop?
Add to this the requirement to allow the remapping of the keyboard commands and the desire for the ability to define keystroke/menu commands to user defined 'macros' (I use the term loosely) and I having trouble envisioning how to build and maintain the hash table.
This is actually quite close to something I'm working on right now, hence my interest.
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
| [reply] |
I'd probably not use a dispatch hash then. Dispatch hashes are more of a smallscale solution. It might make more sense to have classes implementing the actions and various mapping mechanisms that translate from input to method calls. In case of a command line input, a dispatch hash would of course be an obvious approach to implementing such a mapper. In other cases, the mapping may pose very different requirements.
I don't know, it's hard to say without any concrete idea about the requirements of the design you're talking about.
Makeshifts last the longest.
| [reply] |