From 591c8e5daefe8fc8102874838289fe7d82db4d65 Mon Sep 17 00:00:00 2001 From: Alex Kerr Date: Tue, 10 Feb 2015 00:24:18 +0000 Subject: [PATCH] Fixed JSON function --- lib/OSRIC/Character.pm | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/OSRIC/Character.pm b/lib/OSRIC/Character.pm index a6890ad..8b18612 100644 --- a/lib/OSRIC/Character.pm +++ b/lib/OSRIC/Character.pm @@ -21,7 +21,7 @@ use OSRIC::Class::Ranger; use OSRIC::Class::Thief; use OSRIC::Util qw/d/; -use JSON qw/encode_json/; +use JSON qw/to_json/; # These functions are ordered in this file in the order they are to be # called in: @@ -198,10 +198,23 @@ sub generate_gold } # Encodes the character to JSON: -sub to_json +sub as_json { my $self = shift; - my $json = encode_json $self; + my $json = to_json($self, { + pretty => 1, + convert_blessed => 1, + allow_blessed => 1 + }); + return $json; +} + +# Required by the JSON module, as specified in the docs: +sub TO_JSON +{ + my $self = shift; + my %hash = %$self; + return \%hash; } 1;