l loads content into the Plack::Response object
if ($self->res->content_type ne "application/json") { # already UTF8 encoded
my $content = $self->res->content;
my $bytes = encode(
nd_json' => sub {
my $orig = shift;
my $self = shift;
my $data = shift;
my $enc = $conf->get( 'server.encoding.response' => undef );
try {
# calls JSON::XS::encode_json($
if ($self->aborted($err)) { # expected
$self->res->content_type("application/json; charset=$enc") if $enc; # it's already set, but without charset
$err->rethrow;
_for_tests('dies')), poet => $poet);
$self->add_comp(path => '/json.mc', src => encode('UTF-8', $self->content_for_tests('json')), poet => $poet);
}
sub content_for_tests {
my ($self, $wan
ING UNESCAPED: <% uri_unescape(\$m->req->query_string) %>
ASCII
my $src_json = <<SRC;
<\%init>
my \$data_for_json = {
foo => 'bar',
baz => [qw(barp beep)],
9 => { one
\$data_for_json);
SRC
return $src_utf8 if $want eq 'utf8';
return $src_plain if $want eq 'plain';
return $src_utf8_dies if $want eq 'dies';
return $src_json if
e charset');
# utf8 config, json content
$mech->get_ok("http://127.0.0.1:9999/json");
#warn $mech->content;
my $expected_from_json = {
foo => 'bar',
_deeply(JSON->new->utf8->decode($mech->content), $expected_from_json, 'Decoded and de-JSONified expected data from JSON');
# this doesn't work
#my $expected_mangled_from_json = {%$e
xpected_from_json, heart => '�'}; # �
# I can't figure out how to get this test to work. The cmp_deeply fails if fed
# the unmangled hashref as expected, I
#
pe_charset, undef, 'Got correct content-type charset');
# std config, json content
my $expected_from_json = {
foo => 'bar',
baz => [qw(barp beep)],
0.1:9999/json");
#warn $mech->content;
# see comments in UTF8.pm for why I can't use cmp_deeply
#cmp_deeply(JSON->new->utf8->decode($mech->content), $expected_from_json, 'Decod
ected data from JSON'); # fails '�' - that's what is in the content
#cmp_deeply(JSON->new->decode($mech->content), $expected_from_json, 'Decoded expected data from JSON'); # fa