On Tue, Feb 08, 2000 at 05:25:33PM -0500, [EMAIL PROTECTED] wrote:
> well, since we have been on a feature frenzy i thought i would toss in
> this one to the sharks.
> 
> when i have made a serious problem in setting up a callback, event
> generates errors in a loop. i know i should use a $Event::DIED handler
> to deal with this but i think it should wrok better by default. infinite
> error messages is not a good defautl choice IMO. a single error with a
> hard exit would be better to my taste.

Actually, turning errors into warnings is a *feature*.  I've had servers
in production that start crashing and alert the user.  Then I go in with
ProcessTop and, without restarting, work around the problem.  The user
is impressed.

> i will be adding code to verify the object and method exists before
> setting the callback so this will eliminate some potential problems i
> hope.

If your going to be an Event crash dummy, I might as well try to inject
foam into the walls.  How does this look?  Are lexical warnings
extensible?

-- 
"May the best description of competition prevail."
           via, but not speaking for Deutsche Bank
==== //depot/D/Event/c/watcher.c#39 - /cache/D/Event/c/watcher.c ====
--- /tmp/tmp.15790.0    Tue Feb  8 17:46:55 2000
+++ /cache/D/Event/c/watcher.c  Tue Feb  8 17:43:34 2000
@@ -105,8 +105,31 @@
            ev->callback = SvREFCNT_inc(nval);
        } else if (SvROK(nval) &&
                   (SvTYPE(av=(AV*)SvRV(nval)) == SVt_PVAV) &&
-                  av_len(av) == 1 &&
-                  !SvROK(sv=*av_fetch(av, 1, 0))) {
+                  av_len(av) == 1) {
+           /* method lookup code adapted from universal.c */
+           STRLEN n_a;
+           SV *pkgsv = *av_fetch(av, 0, 0);
+           HV *pkg = NULL;
+           SV *namesv = *av_fetch(av, 1, 0);
+           char *name = SvPV(namesv, n_a);
+           int ok=0;
+           if(SvROK(pkgsv)) {
+               pkgsv = (SV*)SvRV(pkgsv);
+               if(SvOBJECT(pkgsv))
+                   pkg = SvSTASH(pkgsv);
+           }
+           else {
+               pkg = gv_stashsv(pkgsv, FALSE);
+           }
+           if (pkg) {
+               GV *gv = gv_fetchmethod_autoload(pkg, name, FALSE);
+               if (gv && isGV(gv))
+                   ok=1;
+           }
+           if (!ok) {
+               warn("Event: callback method %s->%s doesn't exist",
+                    HvNAME(pkg), name);
+           }
            WaPERLCB_on(ev);
            ev->callback = SvREFCNT_inc(nval);
        } else {
==== //depot/D/Event/t/callback.t#3 - /cache/D/Event/t/callback.t ====
--- /tmp/tmp.15790.1    Tue Feb  8 17:46:55 2000
+++ /cache/D/Event/t/callback.t Tue Feb  8 17:46:38 2000
@@ -2,7 +2,7 @@
 
 use strict;
 use Test; plan tests => 3;
-use Event 0.53;
+use Event 0.65;
 
 my $invoked_method=0;
 sub method {
@@ -13,10 +13,14 @@
 Event->timer(after => 0, cb => \&method);
 Event->timer(after => 0, cb => ['main', 'method']);
 Event->timer(after => 0, cb => [$main, 'method']);
+{
+    local $SIG{__WARN__} = sub {
+       ok $_[0], '/nomethod/';
+    };
+    Event->timer(after => 0, cb => [$main, 'nomethod'])->cancel;
+}
 
 eval { Event->timer(after => 0, cb => ['main']); };
-ok $@, '/Callback/';
-eval { Event->timer(after => 0, cb => ['main', \&method]); };
 ok $@, '/Callback/';
 
 Event::loop();

Reply via email to