Skip to content

Instantly share code, notes, and snippets.

@tokuhirom
Created November 28, 2013 04:20
Show Gist options
  • Save tokuhirom/7687208 to your computer and use it in GitHub Desktop.
Save tokuhirom/7687208 to your computer and use it in GitHub Desktop.
{
package HTTP::Body::JSON;
use JSON::XS;
use parent qw(HTTP::Body);
use HTTP::Body;
use Encode qw(encode_utf8);
$HTTP::Body::TYPES->{'application/json'} = __PACKAGE__;
sub spin {
my $self = shift;
return unless $self->length == $self->content_length;
my $dat = JSON::XS::decode_json($self->{buffer});
while (my ($k, $v) = each %$dat) {
$self->param(encode_utf8($k), encode_utf8($v));
}
$self->{buffer} = '';
$self->{state} = 'done';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment