| 1 | package JSON::RPC::Dispatch; | ||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use JSON::RPC::Constants qw(:all); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use JSON::RPC::Parser; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use JSON::RPC::Procedure; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Router::Simple; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | use Class::Accessor::Lite | ||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | rw => [ qw( | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | coder | ||||||||||||||||||||||||||||||||||
| 13 | handlers | ||||||||||||||||||||||||||||||||||
| 14 | parser | ||||||||||||||||||||||||||||||||||
| 15 | prefix | ||||||||||||||||||||||||||||||||||
| 16 | router | ||||||||||||||||||||||||||||||||||
| 17 | ) ] | ||||||||||||||||||||||||||||||||||
| 18 | 2 | ; | |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 21 | 2 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||
| 22 | 2 | my $self = bless { | |||||||||||||||||||||||||||||||||
| 23 | handlers => {}, | ||||||||||||||||||||||||||||||||||
| 24 | @args, | ||||||||||||||||||||||||||||||||||
| 25 | }, $class; | ||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | if (! $self->{coder}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 27 | 1 | require JSON; | |||||||||||||||||||||||||||||||||
| 28 | 1 | $self->{coder} = JSON->new->utf8; | |||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | if (! $self->{parser}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 31 | 1 | $self->{parser} = JSON::RPC::Parser->new( coder => $self->coder ) | |||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | if (! $self->{router}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 34 | 1 | $self->{router} = Router::Simple->new; | |||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||
| 36 | 2 | return $self; | |||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 10 | ▶ | sub guess_handler_class { | ||||||||||||||||||||||||||||||||
|
Subroutine
guess_handler_class: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 40 | 10 | my ($self, $klass) = @_; | |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 10 | ▶ | my $prefix = $self->prefix || ''; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->prefix || ''
MC/DC0%0/1
$self->prefix || ''
$self->prefix
Truth table50%1/2
A
A= $self->prefix
| |||||||||||||||||||||||||||||||||||
| 43 | 10 | return "$prefix\::$klass"; | |||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | 10 | ▶ | sub construct_handler { | ||||||||||||||||||||||||||||||||
|
Subroutine
construct_handler: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 47 | 10 | my ($self, $klass) = @_; | |||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | 10 | my $handler = $self->handlers->{ $klass }; | |||||||||||||||||||||||||||||||||
| 50 | 10 | ▶ | if (! $handler) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 51 | 1 | eval "require $klass"; | |||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | die if $@; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 53 | 1 | $handler = $klass->new(); | |||||||||||||||||||||||||||||||||
| 54 | 1 | $self->handlers->{$klass} = $handler; | |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||
| 56 | 10 | return $handler; | |||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 12 | ▶ | sub get_handler { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_handler: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 60 | 12 | my ($self, $klass) = @_; | |||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | 12 | ▶ | if ( Scalar::Util::blessed( $klass )){ | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 63 | 2 | if (JSONRPC_DEBUG > 1) { | |||||||||||||||||||||||||||||||||
| 64 | warn "Handler is already object : $klass"; | ||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||
| 66 | 2 | return $klass; | |||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 10 | ▶ | if ($klass !~ s/^\+//) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 70 | 10 | $klass = $self->guess_handler_class( $klass ); | |||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 10 | my $handler = $self->construct_handler( $klass ); | |||||||||||||||||||||||||||||||||
| 74 | 10 | if (JSONRPC_DEBUG > 1) { | |||||||||||||||||||||||||||||||||
| 75 | warn "$klass -> $handler"; | ||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||
| 77 | 10 | return $handler; | |||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | 17 | ▶ | sub handle_psgi { | ||||||||||||||||||||||||||||||||
|
Subroutine
handle_psgi: called CC=10 SCAR=23.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 81 | 17 | my ($self, $req, @args) = @_; | |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 17 | ▶ | if ( ! Scalar::Util::blessed($req) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 84 | # assume it's a PSGI hash | ||||||||||||||||||||||||||||||||||
| 85 | 17 | require Plack::Request; | |||||||||||||||||||||||||||||||||
| 86 | 17 | $req = Plack::Request->new($req); | |||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | 17 | my $is_batch = 0; | |||||||||||||||||||||||||||||||||
| 90 | 17 | my @response; | |||||||||||||||||||||||||||||||||
| 91 | my $procedures; | ||||||||||||||||||||||||||||||||||
| 92 | 17 | ▶ | try { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 93 | 17 | $procedures = $self->parser->construct_from_req( $req ); | |||||||||||||||||||||||||||||||||
| 94 | 14 | ▶ | if (ref $procedures eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 95 | 4 | $is_batch = 1; | |||||||||||||||||||||||||||||||||
| 96 | } else { | ||||||||||||||||||||||||||||||||||
| 97 | 10 | $procedures = [$procedures]; | |||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||
| 99 | 14 | ▶ | if (@$procedures <= 0 || not defined $procedures->[0]) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$procedures <= 0 or not defined $procedures->[0]
MC/DC50%1/2
@$procedures <= 0 or not defined $procedures->[0]
@$procedures <= 0
not defined $procedures->[0]
Truth table66%2/3
A or not(B)
A= @$procedures <= 0B= not defined $procedures->[0]
| |||||||||||||||||||||||||||||||||||
| 100 | 1 | $is_batch = 0; | |||||||||||||||||||||||||||||||||
| 101 | 1 | push @response, { | |||||||||||||||||||||||||||||||||
| 102 | error => { | ||||||||||||||||||||||||||||||||||
| 103 | code => RPC_INVALID_REQUEST, | ||||||||||||||||||||||||||||||||||
| 104 | message => "Could not find any procedures" | ||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||
| 106 | }; | ||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||
| 108 | 3 | ▶ | } catch { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 109 | 3 | my $e = $_; | |||||||||||||||||||||||||||||||||
| 110 | 3 | if (JSONRPC_DEBUG) { | |||||||||||||||||||||||||||||||||
| 111 | warn "error while creating jsonrpc request: $e"; | ||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||
| 113 | 3 | ▶ | if ($e =~ /Invalid parameter/) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 114 | 1 | push @response, { | |||||||||||||||||||||||||||||||||
| 115 | error => { | ||||||||||||||||||||||||||||||||||
| 116 | code => RPC_INVALID_PARAMS, | ||||||||||||||||||||||||||||||||||
| 117 | message => "Invalid parameters", | ||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||
| 119 | }; | ||||||||||||||||||||||||||||||||||
| 120 | } elsif ( $e =~ /parse error/ ) { | ||||||||||||||||||||||||||||||||||
| 121 | 1 | push @response, { | |||||||||||||||||||||||||||||||||
| 122 | error => { | ||||||||||||||||||||||||||||||||||
| 123 | code => RPC_PARSE_ERROR, | ||||||||||||||||||||||||||||||||||
| 124 | message => "Failed to parse json", | ||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||||||||
| 127 | } else { | ||||||||||||||||||||||||||||||||||
| 128 | 1 | push @response, { | |||||||||||||||||||||||||||||||||
| 129 | error => { | ||||||||||||||||||||||||||||||||||
| 130 | code => RPC_INVALID_REQUEST, | ||||||||||||||||||||||||||||||||||
| 131 | message => $e | ||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||
| 135 | 17 | }; | |||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||
| 137 | 17 | my $router = $self->router; | |||||||||||||||||||||||||||||||||
| 138 | 17 | foreach my $procedure (@$procedures) { | |||||||||||||||||||||||||||||||||
| 139 | 15 | ▶ | if ( ! $procedure->{method} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 140 | 0 | my $message = "Procedure name not given"; | |||||||||||||||||||||||||||||||||
| 141 | 0 | if (JSONRPC_DEBUG) { | |||||||||||||||||||||||||||||||||
| 142 | warn $message; | ||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||
| 144 | 0 | push @response, { | |||||||||||||||||||||||||||||||||
| 145 | error => { | ||||||||||||||||||||||||||||||||||
| 146 | code => RPC_METHOD_NOT_FOUND, | ||||||||||||||||||||||||||||||||||
| 147 | message => $message, | ||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||
| 149 | }; | ||||||||||||||||||||||||||||||||||
| 150 | 0 | next; | |||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | 15 | ▶ | my $is_notification = defined $procedure->jsonrpc && $procedure->jsonrpc eq '2.0' && !$procedure->has_id; | ||||||||||||||||||||||||||||||||
|
Condition83%5/6
defined $procedure->jsonrpc && $procedure->jsonrpc eq '2.0' && !$procedure->has_id
defined $procedure->jsonrpc and $procedure->jsonrpc eq "2.0"
MC/DC66%2/3
defined $procedure->jsonrpc && $procedure->jsonrpc eq '2.0' && !$procedure->has_id
defined $procedure->jsonrpc
$procedure->jsonrpc eq "2.0"
!$procedure->has_id
Truth table75%3/4
A and B && not(C)
A= defined $procedure->jsonrpcB= $procedure->jsonrpc eq "2.0"C= !$procedure->has_id
| |||||||||||||||||||||||||||||||||||
| 154 | 15 | my $matched = $router->match( $procedure->{method} ); | |||||||||||||||||||||||||||||||||
| 155 | 15 | ▶ | if (! $matched) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 156 | 3 | my $message = "Procedure '$procedure->{method}' not found"; | |||||||||||||||||||||||||||||||||
| 157 | 3 | if (JSONRPC_DEBUG) { | |||||||||||||||||||||||||||||||||
| 158 | warn $message; | ||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||
| 160 | 3 | ▶ | if (!$is_notification) { # must not respond to a valid JSON-RPC notification | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 161 | 2 | push @response, { | |||||||||||||||||||||||||||||||||
| 162 | error => { | ||||||||||||||||||||||||||||||||||
| 163 | code => RPC_METHOD_NOT_FOUND, | ||||||||||||||||||||||||||||||||||
| 164 | message => $message, | ||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||
| 166 | }; | ||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||
| 168 | 3 | next; | |||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||
| 171 | 12 | my $action = $matched->{action}; | |||||||||||||||||||||||||||||||||
| 172 | 12 | ▶ | try { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||
| 173 | 12 | my ($ip, $ua); | |||||||||||||||||||||||||||||||||
| 174 | 12 | if (JSONRPC_DEBUG > 1) { | |||||||||||||||||||||||||||||||||
| 175 | warn "Procedure '$procedure->{method}' maps to action $action"; | ||||||||||||||||||||||||||||||||||
| 176 | $ip = $req->address || 'N/A'; | ||||||||||||||||||||||||||||||||||
| 177 | $ua = $req->user_agent || 'N/A'; | ||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||
| 179 | 12 | my $params = $procedure->params; | |||||||||||||||||||||||||||||||||
| 180 | 12 | my $handler = $self->get_handler( $matched->{handler} ); | |||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | 12 | my $code = $handler->can( $action ); | |||||||||||||||||||||||||||||||||
| 183 | 12 | ▶ | if (! $code) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 184 | 0 | if ( JSONRPC_DEBUG ) { | |||||||||||||||||||||||||||||||||
| 185 | warn "[INFO] handler $handler does not implement method $action!."; | ||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||
| 187 | 0 | die "Internal Error"; | |||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||
| 189 | 12 | my $result = $code->( $handler, $procedure->params, $procedure, @args ); | |||||||||||||||||||||||||||||||||
| 190 | 5 | if (JSONRPC_DEBUG) { | |||||||||||||||||||||||||||||||||
| 191 | warn "[INFO] action=$action " | ||||||||||||||||||||||||||||||||||
| 192 | . "params=[" | ||||||||||||||||||||||||||||||||||
| 193 | . (ref $params ? $self->{coder}->encode($params) : $params) | ||||||||||||||||||||||||||||||||||
| 194 | . "] ret=" | ||||||||||||||||||||||||||||||||||
| 195 | . (ref $result ? $self->{coder}->encode($result) : $result) | ||||||||||||||||||||||||||||||||||
| 196 | . " IP=$ip UA=$ua"; | ||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||
| 199 | # respond unless we are sure a procedure is a notification | ||||||||||||||||||||||||||||||||||
| 200 | 5 | ▶ | if (!$is_notification) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 201 | 5 | push @response, { | |||||||||||||||||||||||||||||||||
| 202 | jsonrpc => '2.0', | ||||||||||||||||||||||||||||||||||
| 203 | result => $result, | ||||||||||||||||||||||||||||||||||
| 204 | id => $procedure->id, | ||||||||||||||||||||||||||||||||||
| 205 | }; | ||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||
| 207 | 7 | ▶ | } catch { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 208 | 7 | my $e = $_; | |||||||||||||||||||||||||||||||||
| 209 | 7 | if (JSONRPC_DEBUG) { | |||||||||||||||||||||||||||||||||
| 210 | warn "Error while executing $action: $e"; | ||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||
| 212 | # can't respond to notifications even in case of errors | ||||||||||||||||||||||||||||||||||
| 213 | 7 | ▶ | if (!$is_notification) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 214 | 4 | my $error = {code => RPC_INTERNAL_ERROR} ; | |||||||||||||||||||||||||||||||||
| 215 | 4 | ▶ | if (ref $e eq "HASH") { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 216 | $error->{message} = $e->{message}, | ||||||||||||||||||||||||||||||||||
| 217 | $error->{data} = $e->{data}, | ||||||||||||||||||||||||||||||||||
| 218 | 1 | } else { | |||||||||||||||||||||||||||||||||
| 219 | 3 | $error->{message} = $e, | |||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||
| 221 | 4 | push @response, { | |||||||||||||||||||||||||||||||||
| 222 | jsonrpc => '2.0', | ||||||||||||||||||||||||||||||||||
| 223 | id => $procedure->id, | ||||||||||||||||||||||||||||||||||
| 224 | error => $error, | ||||||||||||||||||||||||||||||||||
| 225 | }; | ||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||
| 227 | 12 | }; | |||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||
| 230 | 17 | my $res; | |||||||||||||||||||||||||||||||||
| 231 | 17 | ▶ | if (scalar @response) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 232 | 15 | $res = $req->new_response(200); | |||||||||||||||||||||||||||||||||
| 233 | 15 | $res->content_type( 'application/json; charset=utf8' ); | |||||||||||||||||||||||||||||||||
| 234 | 15 | ▶ | $res->body( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 235 | $self->coder->encode( ($is_batch) ? \@response : $response[0] ) | ||||||||||||||||||||||||||||||||||
| 236 | ); | ||||||||||||||||||||||||||||||||||
| 237 | 15 | return $res->finalize; | |||||||||||||||||||||||||||||||||
| 238 | } else { # no content | ||||||||||||||||||||||||||||||||||
| 239 | 2 | $res = $req->new_response(204); | |||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||
| 242 | 2 | return $res->finalize; | |||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||
| 245 | 2 | ▶ | no Try::Tiny; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||
| 247 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||
| 249 | __END__ | ||||||||||||||||||||||||||||||||||