X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FWatchDog.pm;h=bbcd1884077f0efc37ca91ddf9109e2d02f2ddec;hp=3b80f85f90f9711230807b623dd9c67f7508f88f;hb=e42ea8c86203339ab8290ec9f6647778f0bdec1c;hpb=55c0d0209fa9d9265ff178f54ae9fe5fdddef3c1 diff --git a/lib/Object/Remote/WatchDog.pm b/lib/Object/Remote/WatchDog.pm index 3b80f85..bbcd188 100644 --- a/lib/Object/Remote/WatchDog.pm +++ b/lib/Object/Remote/WatchDog.pm @@ -8,13 +8,13 @@ has timeout => ( is => 'ro', required => 1 ); BEGIN { router()->exclude_forwarding; } -around new => sub { - my ($orig, $self, @args) = @_; - our ($WATCHDOG); +sub instance { + my ($class, @args) = @_; - return $WATCHDOG if defined $WATCHDOG; - log_trace { "Constructing new instance of global watchdog" }; - return $WATCHDOG = $self->$orig(@args); + return our $WATCHDOG ||= do { + log_trace { "Constructing new instance of global watchdog" }; + $class->new(@args); + }; }; #start the watchdog @@ -36,9 +36,8 @@ sub BUILD { #invoke at least once per timeout to stop #the watchdog from killing the process sub reset { - our ($WATCHDOG); die "Attempt to reset the watchdog before it was constructed" - unless defined $WATCHDOG; + unless defined our $WATCHDOG; log_debug { "Watchdog has been reset" }; alarm($WATCHDOG->timeout);