Implement guard functions and decorators.

This provides an often simpler alternative to transition tests to
control state-machine execution.