Refactor hooks file.

It was long and rambly. It's also in need of unittesting. So split
it into some classes so that we can test the inputs and outputs
more sensibly.

Change-Id: I3d28f5771e38b819f98a9af06aeb06529be7b302