Skip to content

Commit

Permalink
Item12952: bring back generator method
Browse files Browse the repository at this point in the history
renamed parser() to json() in both Response and Request
  • Loading branch information
MichaelDaum committed Aug 28, 2014
1 parent add0400 commit 9a0e213
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/Foswiki/Contrib/JsonRpcContrib/Request.pm
Expand Up @@ -115,7 +115,7 @@ sub initFromString {
my ( $this, $data ) = @_;

# parse json-rpc request
eval { $this->{data} = $this->parser->decode($data); };
eval { $this->{data} = $this->json->decode($data); };

if ($@) {
my $error = $@;
Expand Down Expand Up @@ -177,14 +177,14 @@ sub namespace {
}

##############################################################################
sub parser {
sub json {
my $this = shift;

unless ( defined $this->{parser} ) {
$this->{parser} = new JSON;
unless ( defined $this->{json} ) {
$this->{json} = new JSON;
}

return $this->{parser};
return $this->{json};
}

################################################################################
Expand Down
9 changes: 8 additions & 1 deletion lib/Foswiki/Contrib/JsonRpcContrib/Response.pm
Expand Up @@ -110,11 +110,18 @@ sub encode {
my $id = $this->id();
$message->{id} = $id if defined $id;

return $this->json->encode($message);
}

################################################################################
sub json {
my $this = shift;

unless ( defined $this->{json} ) {
$this->{json} = JSON->new->pretty(DEBUG)->convert_blessed(1);
}

return $this->{json}->encode($message);
return $this->{json};
}

1;

0 comments on commit 9a0e213

Please sign in to comment.