noodlehaus/dispatch — pull request #42 by nmcgann (2014-02-27 07:20:58+00:00)
Title: Improve route matching to add optional regexes to named parameters, opti...

...onal sections and catchall routes. Updated readme to match.

This makes the named parameters a lot more useful as they can incorporate an optional regex to control what they match.

This regex idea came from the Flight framework (where someone suggested it in an issue and the lead developer thought it was a good idea), but I simplified and modified it to suit dispatch and added the code to avoid problems when optional parameters are missing.

I can't decide whether I like the bracketed optional sections and the match-all asterisk. They preclude full use of regexes, but on the other hand they provide a simpler way of achieving the same result. I think they are probably a good real-world compromise.

A way of having very complex matches would be to modify the way `filter()` works so that all filter functions have to return `true` for the route to proceed. That was actually the first idea I looked at before finding the param+regex technique, but it has the disadvantage that route matching has stopped when filters are called so once a filter fails in the filter chain the only way out is a 404. That limitation could probably be overcome, but it would need major refactoring.