| 1 | package Froody::Renderer::json; | ||
| 2 | 10 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 10 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 10 | ▶ | use JSON::Syck; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 10 | ▶ | use Froody::Response; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 10 | ▶ | use Froody::Response::Terse; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 10 | ▶ | use Encode; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | # If we don't know how to do it ourselves, convert to | ||
| 12 | # a terse and try again | ||
| 13 | 0 | ▶ | *Froody::Response::render_json = sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 14 | 0 | my $self = shift; | |
| 15 | 0 | return $self->as_terse->render_json; | |
| 16 | 10 | }; | |
| 17 | |||
| 18 | # Terse format just gets the main data structure out | ||
| 19 | # and renders it with JSON | ||
| 20 | 0 | ▶ | *Froody::Response::Terse::render_json = sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 21 | 0 | my $self = shift; | |
| 22 | 0 | local $JSON::Syck::ImplicitUnicode = 1; # bah. | |
| 23 | 0 | return Encode::encode_utf8( # BAH | |
| 24 | JSON::Syck::Dump({ stat => $self->status, data => $self->content }) | ||
| 25 | ); | ||
| 26 | 10 | }; | |
| 27 | |||
| 28 | 10 | 1; | |