| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package JSON::RPC::Common::Marshal::HTTP; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | $JSON::RPC::Common::Marshal::HTTP::VERSION = '0.11'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Convert L<HTTP::Request> and L<HTTP::Response> to/from L<JSON::RPC::Common> calls and returns. | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use URI::QueryParam; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use MIME::Base64 (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use HTTP::Response; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use namespace::clean -except => [qw(meta)]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | extends qw(JSON::RPC::Common::Marshal::Text); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | sub _build_json { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_json: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | JSON->new->utf8(1); | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | has prefer_get => ( | |||||||||||||||||||||||||||||||||||||||||
| 24 | isa => "Bool", | ||||||||||||||||||||||||||||||||||||||||||
| 25 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 26 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | has rest_style_methods => ( | |||||||||||||||||||||||||||||||||||||||||
| 30 | isa => "Bool", | ||||||||||||||||||||||||||||||||||||||||||
| 31 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 32 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | has prefer_encoded_get => ( | |||||||||||||||||||||||||||||||||||||||||
| 36 | isa => "Bool", | ||||||||||||||||||||||||||||||||||||||||||
| 37 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 38 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | has expand => ( | |||||||||||||||||||||||||||||||||||||||||
| 42 | isa => "Bool", | ||||||||||||||||||||||||||||||||||||||||||
| 43 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 44 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | has expander => ( | |||||||||||||||||||||||||||||||||||||||||
| 48 | isa => "ClassName|Object", | ||||||||||||||||||||||||||||||||||||||||||
| 49 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | handles => [qw(expand_hash collapse_hash)], | ||||||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub _build_expander { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_expander: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | require CGI::Expand; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return "CGI::Expand"; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | has user_agent => ( | |||||||||||||||||||||||||||||||||||||||||
| 60 | isa => "Str", | ||||||||||||||||||||||||||||||||||||||||||
| 61 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 62 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | sub _build_user_agent { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_user_agent: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | require JSON::RPC::Common; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | join(" ", ref($self), $JSON::RPC::Common::VERSION), | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | has content_type => ( | |||||||||||||||||||||||||||||||||||||||||
| 72 | isa => "Str", | ||||||||||||||||||||||||||||||||||||||||||
| 73 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 74 | predicate => "has_content_type", | ||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | has content_types => ( | |||||||||||||||||||||||||||||||||||||||||
| 78 | isa => "HashRef[Str]", | ||||||||||||||||||||||||||||||||||||||||||
| 79 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 80 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | sub _build_content_types { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_content_types: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | "1.0" => "application/json", | |||||||||||||||||||||||||||||||||||||||||
| 86 | "1.1" => "application/json", | ||||||||||||||||||||||||||||||||||||||||||
| 87 | "2.0" => "application/json-rpc", | ||||||||||||||||||||||||||||||||||||||||||
| 88 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | has accept_content_type => ( | |||||||||||||||||||||||||||||||||||||||||
| 92 | isa => "Str", | ||||||||||||||||||||||||||||||||||||||||||
| 93 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 94 | predicate => "has_accept_content_type", | ||||||||||||||||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | has accept_content_types => ( | |||||||||||||||||||||||||||||||||||||||||
| 98 | isa => "HashRef[Str]", | ||||||||||||||||||||||||||||||||||||||||||
| 99 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 100 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | sub _build_accept_content_types { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_accept_content_types: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | "1.0" => "application/json", | |||||||||||||||||||||||||||||||||||||||||
| 106 | "1.1" => "application/json", | ||||||||||||||||||||||||||||||||||||||||||
| 107 | "2.0" => "application/json-rpc", | ||||||||||||||||||||||||||||||||||||||||||
| 108 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 16 | ▶ | sub get_content_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_content_type: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 16 | my ( $self, $obj ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 16 | ▶ | if ( $self->has_content_type ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return $self->content_type; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 16 | ▶ | return $self->content_types->{ $obj->version || "2.0" }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$obj->version || '2.0'
MC/DC0%0/1
$obj->version || '2.0'
$obj->version
Truth table50%1/2
A
A= $obj->version
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 30 | ▶ | sub get_accept_content_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_accept_content_type: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 30 | my ( $self, $obj ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 30 | ▶ | if ( $self->has_accept_content_type ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | return $self->accept_content_type; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 30 | ▶ | return $self->accept_content_types->{ $obj->version || "2.0" }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$obj->version || '2.0'
MC/DC0%0/1
$obj->version || '2.0'
$obj->version
Truth table50%1/2
A
A= $obj->version
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 30 | ▶ | sub call_to_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call_to_request: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 30 | my ( $self, $call, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 30 | ▶ | $args{prefer_get} = $self->prefer_get unless exists $args{prefer_get}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 30 | ▶ | if ( $args{prefer_get} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 16 | return $self->call_to_get_request($call, %args); | |||||||||||||||||||||||||||||||||||||||||
| 138 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 14 | return $self->call_to_post_request($call, %args); | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 14 | ▶ | sub call_to_post_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call_to_post_request: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 14 | my ( $self, $call, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 14 | my $uri = $self->call_reconstruct_uri_base($call, @args); | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 14 | my $encoded = $self->call_to_json($call); | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 14 | my $headers = HTTP::Headers->new( | |||||||||||||||||||||||||||||||||||||||||
| 151 | User_Agent => $self->user_agent, | ||||||||||||||||||||||||||||||||||||||||||
| 152 | Content_Type => $self->get_content_type($call), | ||||||||||||||||||||||||||||||||||||||||||
| 153 | Accept => $self->get_accept_content_type($call), | ||||||||||||||||||||||||||||||||||||||||||
| 154 | Content_Length => length($encoded), | ||||||||||||||||||||||||||||||||||||||||||
| 155 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 14 | return HTTP::Request->new( POST => $uri, $headers, $encoded ); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 16 | ▶ | sub call_to_get_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call_to_get_request: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 16 | my ( $self, $call, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 16 | my $uri = $self->call_to_uri($call, @args); | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 16 | my $headers = HTTP::Headers->new( | |||||||||||||||||||||||||||||||||||||||||
| 166 | User_Agent => $self->user_agent, | ||||||||||||||||||||||||||||||||||||||||||
| 167 | Accept => $self->get_accept_content_type($call), | ||||||||||||||||||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 16 | HTTP::Request->new( GET => $uri, $headers ); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 16 | ▶ | sub call_to_uri { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call_to_uri: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 16 | my ( $self, $call, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | my $prefer_encoded_get = exists $args{encoded} | ||||||||||||||||||||||||||||||||||||||||||
| 178 | ? $args{encoded} | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 16 | ▶ | : ( $call->version eq '2.0' || $self->prefer_encoded_get ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$call->version eq "2.0" or $self->prefer_encoded_get
MC/DC0%0/2
$call->version eq "2.0" or $self->prefer_encoded_get
$call->version eq "2.0"
$self->prefer_encoded_get
Truth table0%0/3
A or B
A= $call->version eq "2.0"B= $self->prefer_encoded_get
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 16 | ▶ | if ( $prefer_encoded_get ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 7 | return $self->call_to_encoded_uri($call, %args); | |||||||||||||||||||||||||||||||||||||||||
| 183 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 9 | return $self->call_to_query_uri($call, %args); | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 30 | ▶ | sub call_reconstruct_uri_base { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call_reconstruct_uri_base: called CC=4 SCAR=19.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 30 | my ( $self, $call, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 30 | ▶ | if ( my $base_path = $args{base_path} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 10 | return URI->new($base_path); | |||||||||||||||||||||||||||||||||||||||||
| 193 | } elsif ( my $uri = $args{uri} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $uri = $uri->clone; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ( my $path_info = $args{path_info} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $path = $uri->path; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $path =~ s/\Q$path_info\E$//; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $uri->path($path); | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | return $uri; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 20 | URI->new('/'); | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 7 | ▶ | sub call_to_encoded_uri { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call_to_encoded_uri: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 7 | my ( $self, $call, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 7 | my $uri = $self->call_reconstruct_uri_base($call, @args); | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 7 | my $deflated = $self->deflate_call($call); | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 7 | my ( $method, $params, $id ) = delete @{ $deflated }{qw(method params id)}; | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 7 | my $encoded = $self->encode_base64( $self->encode($params) ); | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 7 | $uri->query_param( params => $encoded ); | |||||||||||||||||||||||||||||||||||||||||
| 220 | 7 | $uri->query_param( method => $method ); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 7 | ▶ | $uri->query_param( id => $id ) if $call->has_id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 7 | return $uri; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 9 | ▶ | sub call_to_query_uri { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call_to_query_uri: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 9 | my ( $self, $call, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 9 | my $uri = $self->call_reconstruct_uri_base($call, %args); | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 9 | my $deflated = $self->deflate_call( $call ); | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 9 | my ( $method, $params, $id ) = delete @{ $deflated }{qw(method params id)}; | |||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 9 | $params = $self->collapse_query_params($params); | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 9 | $uri->query_form( %$params, id => $id ); | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 9 | ▶ | if ( exists $args{rest_style_methods} ? $args{rest_style_methods} : $self->rest_style_methods ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 7 | my $path = $uri->path; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 7 | $path =~ s{/?$}{"/" . $method}e; # add method, remove double trailing slash | |||||||||||||||||||||||||||||||||||||||||
| 242 | 7 | $uri->path($path); | |||||||||||||||||||||||||||||||||||||||||
| 243 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | $uri->query_param( method => $method ); | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 9 | return $uri; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 37 | ▶ | sub request_to_call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request_to_call: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 37 | my ( $self, $request, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 37 | my $req_method = lc( $request->method . "_request_to_call" ); | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 37 | ▶ | if ( my $code = $self->can($req_method) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 37 | $self->$code($request, @args); | |||||||||||||||||||||||||||||||||||||||||
| 257 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | croak "Unsupported HTTP request method " . $request->method; | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 22 | ▶ | sub get_request_to_call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_request_to_call: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 22 | my ( $self, $request, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 22 | $self->uri_to_call(request => $request, @args); | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 22 | ▶ | sub uri_to_call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uri_to_call: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 22 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 22 | ▶ | my $uri = $args{uri} || ($args{request} || croak "Either 'uri' or 'request' is mandatory")->uri; | ||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$args{'uri'} || ($args{'request'} || croak(q[Either 'uri' or 'request' is mandatory]))->uri
$args{'request'} || croak(q[Either 'uri' or 'request' is mandatory])
MC/DC0%0/2
$args{'uri'} || ($args{'request'} || croak(q[Either 'uri' or 'request' is mandatory]))->uri
$args{'uri'}
($args{'request'} || croak(q[Either 'uri' or 'request' is mandatory]))->uri
MC/DC0%0/1
$args{'request'} || croak(q[Either 'uri' or 'request' is mandatory])
$args{'request'}
Truth table33%1/3
A || B
A= $args{'uri'}B= ($args{'request'} || croak(q[Either 'uri' or 'request' is mandatory]))->uri
Truth table50%1/2
A
A= $args{'request'}
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 22 | my $params = $uri->query_form_hash; | |||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 22 | ▶ | if ( exists $params->{params} and $self->prefer_encoded_get ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $params->{"params"} and $self->prefer_encoded_get
MC/DC50%1/2
exists $params->{"params"} and $self->prefer_encoded_get
exists $params->{"params"}
$self->prefer_encoded_get
Truth table66%2/3
A and B
A= exists $params->{"params"}B= $self->prefer_encoded_get
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 9 | return $self->encoded_uri_to_call( $uri, %args ); | |||||||||||||||||||||||||||||||||||||||||
| 277 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 13 | return $self->query_uri_to_call( $uri, %args ); | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 8 | ▶ | sub decode_base64 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_base64: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 8 | my ( $self, $base64 ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 8 | MIME::Base64::decode_base64($base64); | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 7 | ▶ | sub encode_base64 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_base64: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 7 | my ( $self, $base64 ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 7 | MIME::Base64::encode_base64($base64); | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | # the sane way, 1.1-alt | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 9 | ▶ | sub encoded_uri_to_call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encoded_uri_to_call: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 9 | my ( $self, $uri, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 9 | my $params = $uri->query_form_hash; | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | # the 'params' URI param is encoded as JSON, inflate it | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 9 | my %rpc = %$params; | |||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 9 | ▶ | $rpc{version} ||= "2.0"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rpc{"version"} ||= "2.0"
MC/DC100%1/1
$rpc{"version"} ||= "2.0"
$rpc{"version"}
Truth table100%2/2
A
A= $rpc{"version"}
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 9 | for my $params ( $rpc{params} ) { | |||||||||||||||||||||||||||||||||||||||||
| 304 | # try as unencoded JSON first | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 9 | ▶ | if ( my $data = try { $self->decode($params) } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | $params = $data; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 8 | ▶ | my $json = $self->decode_base64($params) || croak "params are not Base64 encoded"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->decode_base64($params) || croak('params are not Base64 encoded')
MC/DC0%0/1
$self->decode_base64($params) || croak('params are not Base64 encoded')
$self->decode_base64($params)
Truth table50%1/2
A
A= $self->decode_base64($params)
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 8 | $params = $self->decode($json); | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 9 | $self->inflate_call(\%rpc); | |||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | # the less sane but occasionally useful way, 1.1-wd | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 13 | ▶ | sub query_uri_to_call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_uri_to_call: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 13 | my ( $self, $uri, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 13 | my $params = $uri->query_form_hash; | |||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 13 | my %rpc = ( params => $params ); | |||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 13 | foreach my $key (qw(version jsonrpc method id) ) { | |||||||||||||||||||||||||||||||||||||||||
| 325 | 52 | ▶ | if ( exists $params->{$key} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 20 | $rpc{$key} = delete $params->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 13 | ▶ | if ( !exists($rpc{method}) and $args{rest_style_methods} || $self->rest_style_methods ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not exists $rpc{"method"} and $args{"rest_style_methods"} || $self->rest_style_methods
$args{"rest_style_methods"} or $self->rest_style_methods
MC/DC33%1/3
not exists $rpc{"method"} and $args{"rest_style_methods"} || $self->rest_style_methods
not exists $rpc{"method"}
$args{"rest_style_methods"}
$self->rest_style_methods
Truth table50%2/4
not(A) and B or C
A= not exists $rpc{"method"}B= $args{"rest_style_methods"}C= $self->rest_style_methods
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 10 | ▶ | if ( my $path_info = $args{path_info} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 2 | ( $rpc{method} = $path_info ) =~ s{^/}{}; | |||||||||||||||||||||||||||||||||||||||||
| 333 | } elsif ( my $base = $args{base_path} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | my ( $method ) = ( $uri->path =~ m{^\Q$base\E(.*)$} ); | |||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | $method =~ s{^/}{}; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 2 | $rpc{method} = $method; | |||||||||||||||||||||||||||||||||||||||||
| 337 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 6 | my ( $method ) = ( $uri->path =~ m{/(\w+)$} ); | |||||||||||||||||||||||||||||||||||||||||
| 339 | 6 | $rpc{method} = $method; | |||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 13 | ▶ | $rpc{version} ||= "1.1"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rpc{"version"} ||= "1.1"
MC/DC100%1/1
$rpc{"version"} ||= "1.1"
$rpc{"version"}
Truth table100%2/2
A
A= $rpc{"version"}
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | # increases usefulness | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 13 | $rpc{params} = $self->expand_query_params($params, %args); | |||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 13 | $self->inflate_call(\%rpc); | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 13 | ▶ | sub expand_query_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand_query_params: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 13 | my ( $self, $params, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 13 | ▶ | if ( $self->expand ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | return $self->expand_hash($params); | |||||||||||||||||||||||||||||||||||||||||
| 356 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 13 | return $params; | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 9 | ▶ | sub collapse_query_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collapse_query_params: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 9 | my ( $self, $params, $request, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 9 | ▶ | if ( $self->expand ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | return $self->collapse_hash($params); | |||||||||||||||||||||||||||||||||||||||||
| 366 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 9 | return $params; | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 15 | ▶ | sub post_request_to_call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
post_request_to_call: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 15 | my ( $self, $request ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 15 | $self->json_to_call( $request->content ); | |||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | sub write_result_to_response { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_result_to_response: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | my ( $self, $result, $response, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my %args = $self->result_to_response_params($result); | |||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | foreach my $key ( keys %args ) { | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | if ( $response->can($key) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $response->$key(delete $args{$key}); | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if (my @keys = keys %args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | croak "Unhandled response params: " . join ' ', @keys; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 5 | ▶ | sub response_to_result { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response_to_result: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 5 | my ( $self, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 5 | ▶ | if ( $response->is_success ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 2 | $self->response_to_result_success($response); | |||||||||||||||||||||||||||||||||||||||||
| 399 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 3 | $self->response_to_result_error($response); | |||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 2 | ▶ | sub response_to_result_success { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response_to_result_success: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 2 | my ( $self, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 2 | $self->json_to_return( $response->content ); | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 3 | ▶ | sub response_to_result_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response_to_result_error: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 3 | my ( $self, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 3 | my $res = $self->json_to_return( $response->content ); | |||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 3 | ▶ | unless ( $res->has_error ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | $res->set_error( | |||||||||||||||||||||||||||||||||||||||||
| 417 | message => $response->message, | ||||||||||||||||||||||||||||||||||||||||||
| 418 | code => $response->code, # FIXME dictionary | ||||||||||||||||||||||||||||||||||||||||||
| 419 | data => { | ||||||||||||||||||||||||||||||||||||||||||
| 420 | response => $response, | ||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 3 | return $res; | |||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 2 | ▶ | sub result_to_response { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result_to_response: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 2 | my ( $self, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 2 | $self->create_http_response( $self->result_to_response_headers($result) ); | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 2 | ▶ | sub create_http_response { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_http_response: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 2 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | 2 | my ( $body, $status ) = delete @args{qw(body status)}; | |||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 2 | HTTP::Response->new( | |||||||||||||||||||||||||||||||||||||||||
| 440 | $status, | ||||||||||||||||||||||||||||||||||||||||||
| 441 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 442 | HTTP::Headers->new(%args), | ||||||||||||||||||||||||||||||||||||||||||
| 443 | $body, | ||||||||||||||||||||||||||||||||||||||||||
| 444 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 2 | ▶ | sub result_to_response_headers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result_to_response_headers: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 2 | my ( $self, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 2 | my $body = $self->encode($result->deflate); | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 2 | ▶ | status => ( $result->has_error ? $result->error->http_status : 200 ), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | Content_Type => $self->get_content_type($result), | ||||||||||||||||||||||||||||||||||||||||||
| 455 | Content_Length => length($body), # http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#ResponseHeaders | ||||||||||||||||||||||||||||||||||||||||||
| 456 | body => $body, | ||||||||||||||||||||||||||||||||||||||||||
| 457 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | sub result_to_response_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result_to_response_params: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | my ( $self, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | my %headers = $self->result_to_response_headers($result); | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | $headers{content_type} = delete $headers{Content_Type}; | |||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $headers{content_length} = delete $headers{Content_Length}; | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | return %headers; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 1 | __PACKAGE__->meta->make_immutable(); | |||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 1 | __PACKAGE__ | |||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | __END__ | ||||||||||||||||||||||||||||||||||||||||||