From 474d0eda557d8d68904a01c8a27b5017676d08ad Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Sat, 2 May 2020 18:10:02 -0400 Subject: [PATCH] Euchre::Player: Add send method This makes the websocket field transparent to callers. --- lib/Euchre/Dealer.pm | 6 +++--- lib/Euchre/Player.pm | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm index 6841a1f..e8e066b 100644 --- a/lib/Euchre/Dealer.pm +++ b/lib/Euchre/Dealer.pm @@ -121,7 +121,7 @@ sub handle_msg { sub pong { my ($p) = @_; - $p->ws->send({ json => { msg_type => 'pong' } }); + $p->send({ msg_type => 'pong' }); } # player_name @@ -540,7 +540,7 @@ sub broadcast_gamestate { hand => $p->hand, is_spectator => ($p->seat) ? 0 : 1, }; - $p->ws->send({ json => $json }); + $p->send($json); } } @@ -663,7 +663,7 @@ sub chat { msg_type => 'chat', msg => "$p->name: $msg->{msg}" }; - $player->ws->send({ json => $json }); + $player->send($json); } } diff --git a/lib/Euchre/Player.pm b/lib/Euchre/Player.pm index cf9c7ce..dbcdf80 100644 --- a/lib/Euchre/Player.pm +++ b/lib/Euchre/Player.pm @@ -28,7 +28,13 @@ sub error { errno => $errno, msg => err_msg($errno), }; - $self->ws->send({ json => $json}); + $self->send($json); +} + +# Send a JSON message +sub send { + my ($self, $json) = @_; + $self->ws->send({ json => $json }); } 1; -- libgit2 1.1.1