Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow JSON object to be set #15

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/Tatsumaki/Handler.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ has args => (is => 'rw', isa => 'ArrayRef');
has writer => (is => 'rw'); has writer => (is => 'rw');
has mxhr => (is => 'rw', isa => 'Bool'); has mxhr => (is => 'rw', isa => 'Bool');
has mxhr_boundary => (is => 'rw', isa => 'Str', lazy => 1, lazy_build => 1); has mxhr_boundary => (is => 'rw', isa => 'Str', lazy => 1, lazy_build => 1);
has json => (is => 'rw', isa => 'JSON', lazy => 1, default => sub { JSON->new->utf8 });


has _write_buffer => (is => 'rw', isa => 'ArrayRef', lazy => 1, default => sub { [] }); has _write_buffer => (is => 'rw', isa => 'ArrayRef', lazy => 1, default => sub { [] });


Expand Down Expand Up @@ -165,11 +166,11 @@ sub get_chunk {
my $self = shift; my $self = shift;
if (ref $_[0]) { if (ref $_[0]) {
if ($self->mxhr) { if ($self->mxhr) {
my $json = JSON::encode_json($_[0]); my $json = $self->json->encode($_[0]);
return "Content-Type: application/json\n\n$json\n--" . $self->mxhr_boundary. "\n"; return "Content-Type: application/json\n\n$json\n--" . $self->mxhr_boundary. "\n";
} else { } else {
$self->response->content_type('application/json'); $self->response->content_type('application/json');
return JSON::encode_json($_[0]); return $self->json->encode($_[0]);
} }
} else { } else {
join '', map Encode::encode_utf8($_), @_; join '', map Encode::encode_utf8($_), @_;
Expand Down