towers are constructable
[scpubgit/Clifton.git] / lib / App / Clifton / Component.pm
index 7b153f0..7f80acd 100644 (file)
@@ -35,9 +35,29 @@ sub _new_child {
   }
 }
 
+around _replace_weakself => sub {
+  my ($orig, $self) = (shift, shift);
+  $self->_eval_cb($self->$orig(@_));
+};
+
+around _capture_weakself => sub {
+  my ($orig, $self) = (shift, shift);
+  $self->_eval_cb($self->$orig(@_));
+};
+
 sub _schedule {
   my ($self, $code) = @_;
-  $self->get_loop->later($code);
+  $self->get_loop->later($self->_eval_cb($code));
+}
+
+sub _eval_cb {
+  my ($self, $code) = @_;
+  my $str = "$self";
+  sub {
+    local $@;
+    eval { $code->(@_); 1 }
+      or log_error { "Exception from ${self}: $@" };
+  };
 }
 
 sub DESTROY {