Counting Hooks
This (fairly long) one-liner counts the number of implementations of each hook in your Drupal installation:
ack "Implements? hook_" | perl -e 'while (<>) { m[(hook_\w+)] and $hooks{$1}++; } foreach (keys %hooks) { print "$_ - $hooks{$_}\n"; }'To count only install file hooks, which was what I was doing, give ack the option "-G '.install'" thus:
ack "Implements? hook_" -G '.install' | perl -e 'while (<>) { m[(hook_\w+)] and $hooks{$1}++; } foreach (keys %hooks) { print "$_ - $hooks{$_}\n"; }'You can probably adapt this for grep. Ack is far better though (proper regular expressions and sensible assumptions for starters).
Unfortunately, now I've taken ten minutes to do this, I've completely forgotten what I needed to count hooks for. So I'm posting this so by the time I remember I can come back to it!
Edit: Oh yes. I was generating a list of hooks implemented in .install files (just a list, the count is bonus) to check I'd covered everything in my patch for hook locations in the documentation.


Thank you for some help
Thank you for some help
relies on comments
The problem with this approach is that it relies on comments
It won't pick up any hooks that don't have the comment.
It will miss comments like "implementation of hook_"
And will generate false positives for comments like "an alternative way of achieving this would be to implement hook_"
It's pretty tricky to count hook use in Drupal because hooks are so poorly defined.
It's the sort of thing that the Devel module could do if there was a hook controller of some sort.
http://drupal.org/node/353494 suggests merging some of the invoke functions which would help - but doesn't seem to be moving fast
Post new comment