rewrite ListenerService's DEMOLISH method for sanity and clarity
Matt S Trout [Tue, 6 Dec 2011 22:39:44 +0000 (22:39 +0000)]
lib/Tak/Daemon/ListenerService.pm

index 95c0499..1751ab5 100644 (file)
@@ -76,12 +76,15 @@ sub handle_stop {
 }
 
 sub DEMOLISH {
-  my ($self, $gd) = @_;
-  return if $gd;
-  if (my $l = $self->listener) {
-    $l->get_loop->remove($l);
-    unlink($self->socket_location);
-  }
+  my ($self, $in_global_destruction) = @_;
+
+  return unless $self->state eq 'running';
+
+  unlink($self->socket_location);
+
+  return if $in_global_destruction;
+
+  Tak->loop->remove($self->listener);
 }
 
 sub setup_connection {