Saturday, April 10, 2010

Prefixes

I introduced prefixes in the 9.x releases. They were a basic shortcut technique: add a single character before a name to alter the behavior. The original code used a non-editable table for determining which characters were valid and the new behaviors the prefixes would introduce. When adding prefixes to the current Retro, I took a different approach.

Prefixes are handled by words, with a consistent naming format: __X where X is the prefix character. I also added a prefixes vocabulary, allowing the prefixes to be toggled on and off simply.

The notfound error handler was extended to search for prefix words if a name isn't found in the dictionary. If the prefix is found, and the rest of the name is found, the word is passed to the prefix handler.

The end result is a clean, extensible way of handling, adding, and replacing prefixes. Plus, they can easily be disabled or enabled as desired.

No comments: