towers are constructable
[scpubgit/Clifton.git] / lib / App / Clifton / ConsoleService.pm
index 4ca0e73..7e13f01 100644 (file)
@@ -4,7 +4,6 @@ use Log::Contextual qw(:log);
 use aliased 'App::Clifton::ConsoleService::Session';
 use IO::Async::Listener;
 use IO::Socket::UNIX;
-use Scalar::Util qw(weaken);
 use Moo;
 
 extends 'App::Clifton::Service';
@@ -13,6 +12,8 @@ has socket_location => (is => 'ro', default => sub { 'clifton.sock' });
 
 has $_ => (is => 'lazy') for qw(listener session socket);
 
+has server => (is => 'ro', required => 1, weak_ref => 1);
+
 sub _build_socket {
   my ($self) = @_;
   my $location = $self->socket_location;
@@ -35,8 +36,8 @@ sub _build_session {
   my ($self) = @_;
   Session->new->${\sub {
     my ($session) = @_;
-    $session->lex_env->lexicals->{'$_SERVICE'} = \$self;
-    weaken(${$session->lex_env->{'$_SERVICE'}});
+    # no need to weaken this since server is already weak
+    $session->lex_env->lexicals->{'$_SERVER'} = \$self->server;
     $session;
   }};
 }