From ed46a8246a3d487d59a550033901ed6d9c5dc2ee Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Tue, 31 Mar 2020 23:54:57 -0400 Subject: [PATCH] Euchre::Dealer: Fix double JSON encoding I was wondering when I whipped up the prototype why I needed to call JSON.parses() twice... Turns out ws->send() encodes it for us, so there's no need to use encode_json explicitly! --- lib/Euchre/Dealer.pm | 9 ++++----- public/debug.html | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm index e7d742b..26fcfcc 100644 --- a/lib/Euchre/Dealer.pm +++ b/lib/Euchre/Dealer.pm @@ -5,7 +5,6 @@ use warnings; package Euchre::Dealer; use List::Util; -use Mojo::JSON qw(encode_json); use Euchre::Card; use Euchre::Game; @@ -225,11 +224,11 @@ sub deal_players_hands { for my $p (@{$game->{players}}) { my @hand = map { cid_to_name($_) } @{shift @$handsA}; $p->{ws}->send({ json => - encode_json({ + { msg_type => 'deal', hand => \@hand, trump_nominee => $nominee, - }) + } }); } } @@ -254,7 +253,7 @@ sub broadcast_gamestate { spectators => \@snames, }; - my $json = encode_json({ msg_type => 'game_state', game => $msg }); + my $json = { msg_type => 'game_state', game => $msg }; for my $ws (@all_ws) { $ws->send({ json => $json}); } @@ -264,7 +263,7 @@ sub broadcast_gamestate { sub send_error { my ($p, $msg) = @_; my $ws = $p->{ws}; - my $json = encode_json({ msg_type => 'error', msg => $msg }); + my $json = { msg_type => 'error', msg => $msg }; $ws->send({ json => $json}); } diff --git a/public/debug.html b/public/debug.html index 892d90c..a3f2d1c 100644 --- a/public/debug.html +++ b/public/debug.html @@ -9,7 +9,7 @@