A var watcher can currently be created with no variable to watch, provided
of course that it is parked.  However, once a variable has been set,
the watcher cannot be returned to the no-variable state.  The variable
to watch can be changed, but the watcher rejects any attempt to set the
reference to undef.  I think this is a bug: other watchers generally
allow themselves to be put into an unconfigured, unrunnable state.

The patch below allows the variable reference of a var watcher to be set
to undef.  I've tested this: in the undef state it refuses to be started;
it stops if put into the undef state; and it still rejects defined values
other than references to watchable scalars.

--- c/var.c     2003-02-18 16:25:28.000000000 +0000
+++ c/var.c     2004-11-28 23:23:39.000000000 +0000
@@ -150,10 +150,12 @@
     if (nval) {
        SV *old = vp->variable;
        int active = WaPOLLING(ev);
-       if (!SvROK(nval))
-           croak("Expecting a reference");
-       if (SvTYPE(SvRV(nval)) > SVt_PVMG)
-           croak("Var watchers can only watch plain vanilla scalars");
+       if (SvOK(nval)) {
+           if (!SvROK(nval))
+               croak("Expecting a reference");
+           if (SvTYPE(SvRV(nval)) > SVt_PVMG)
+               croak("Var watchers can only watch plain vanilla scalars");
+       }
        if (active) pe_watcher_off(ev);
        vp->variable = SvREFCNT_inc(nval);
        if (active) pe_watcher_on(ev, 0);

-zefram

Reply via email to