From: Johan L. <jo...@Da...> - 2004-01-08 19:35:28
|
At 02:33 2004-01-08, Steve Pick wrote: >When removing hooks they are identified by coderef, so this is WRONG: > >$win->Hook(WM_MOVE, sub { print "moved!" }); >$win->UnHook(WM_MOVE, sub { print "moved!" }); > >In that case, UnHook will return false and the hook will not be removed >because the codref passed to the UnHook call will be different to the one >passed to Hook. You should do it like this: > >$movedsub = sub { print "moved!\n" }; >$win->Hook(WM_MOVE, $movedsub); >$win->UnHook(WM_MOVE, $movedsub); I'm sorry but, from the outside, doesn't this seem slightly illogical? What happens if you do: $win->Hook(WM_MOVE, $mysub); $win->Hook(WM_MOVE, $myothersub); or even using the same handler for two windows: $win->Hook(WM_MOVE, $mysub); $win2->Hook(WM_MOVE, $mysub); Would that result in weirdness? Would it not be more logical to key the hook by the $win and the message (WM_MOVE) rather than the handler coderef? 1) No strange semantics. 2) No need to remember what I happened to hook it with. Or is it just me? :) /J -------- ------ ---- --- -- -- -- - - - - - Johan Lindström Sourcerer @ Boss Casinos jo...@Da... Latest bookmark: "Open Text Summarizer" http://libots.sourceforge.net/ dmoz (1 of 6): /Computers/Software/Operating_Systems/Linux/ 9 |