[Zope-PTK] Hooks

Fabio Forno sciasbat@inorbit.com
Fri, 18 Aug 2000 19:36:31 +0200


Shane Hathaway wrote:

> > if hasattr(self,'hook_function'):
> >   self.hook_function()
> 
> Okay, I think what we'll do is create versions of the tools that
> provide hooks in the right places.  It would be beneficial if you would
> list for us the hooks we ought to provide (such as
> WorkflowTool.beforeChangeState(), WorkflowTool.afterChangeState(),
> etc.)

Perhaps it's a crazy idea, but what about a fully configurable hook map,
so that we allow the users to add the hook they want?

If I need an hook 'X' for the method 'Y', I add the 'Y':'X' pair into
the hook map, so that 'X' is called automagically by 'Y'

The schema could be something like:

if hook_map.has_key('Y'):
  f=getattr(self,hook_map['Y'])
  f(same params as this method)

All the tools could be derived from a Hookable class, containing the
hook dictionary and an apply_hook method which does the job described
before. 

In addition for each method 'Y' there could be two labels 'beforeY'
'afterY', to discriminate between the two types of hooks.

ByE,
FF