Group
Extension

Matches 4

Mason-Plugin-WithEncoding ( D/DA/DAVEBAIRD/Mason-Plugin-WithEncoding-0.2.tar.gz, DAVEBAIRD, 2016; MetaCPAN )
Mason-Plugin-WithEncoding/lib/Mason/Plugin/WithEncoding.pm ( view source; MetaCPAN )
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;
     
Mason-Plugin-WithEncoding ( D/DA/DAVEBAIRD/Mason-Plugin-WithEncoding-0.2.tar.gz, DAVEBAIRD, 2016; MetaCPAN )
Mason-Plugin-WithEncoding/lib/Mason/Plugin/WithEncoding/Test/Class.pm ( view source; MetaCPAN )
_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
Mason-Plugin-WithEncoding ( D/DA/DAVEBAIRD/Mason-Plugin-WithEncoding-0.2.tar.gz, DAVEBAIRD, 2016; MetaCPAN )
Mason-Plugin-WithEncoding/lib/Mason/Plugin/WithEncoding/t/UTF8.pm ( view source; MetaCPAN )
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
        #  
Mason-Plugin-WithEncoding ( D/DA/DAVEBAIRD/Mason-Plugin-WithEncoding-0.2.tar.gz, DAVEBAIRD, 2016; MetaCPAN )
Mason-Plugin-WithEncoding/lib/Mason/Plugin/WithEncoding/t/NoUTF8.pm ( view source; MetaCPAN )
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

Powered by Groonga
Maintained by Kenichi Ishigaki <ishigaki@cpan.org>. If you find anything, submit it on GitHub.